Skip to content

Commit

Permalink
fix: Fix examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Feb 17, 2022
1 parent 967ef25 commit 8656c94
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ fun main() {
backgroundColor = Color(120, 200, 230)
resizeTo = window
}
app.addToBody()

val bunny = Sprite.from("bunny.png")
bunny.setPositionFromWindow(0.5, 0.5)
bunny.anchor.set(0.5)
bunny.addToApplication(app)
val bunny = Sprite.from("bunny.png").apply {
setPositionFromWindow(0.5, 0.5)
anchor.set(0.5)
interactive = true
addToApplication(app)
}

bunny.on(DisplayObjectEvents.click) {
bunny.on(DisplayObjectEvents.mousedown) {
bunny.scale.set(1.1)
}

bunny.on(DisplayObjectEvents.mouseup) {
bunny.scale.set(1)
bunny.scale.set(1.0)
}
}
```
Expand All @@ -58,6 +61,7 @@ fun main() {
val app = Application {
resizeTo = window
}
app.addToBody()

val english = "en" in window.navigator.languages.elementAtOrElse(0) { window.navigator.language }

Expand All @@ -72,12 +76,14 @@ fun main() {
)

val sprite = Sprite(generateBlankTexture(app) {
width = 300
height = 300
color = Color(0xFF0000)
width = 300.0
height = 300.0
color = Color(255, 0, 0)
})
sprite.addToApplication(app)
sprite.setPositionFromApplication(app, 0.5, 0.5)

val area = Rectangle(0, 0, app.screen.width, app.screen.height)
val area = Rectangle(0.0, 0.0, app.screen.width, app.screen.height)

keyMap.onPress("forward") {
sprite.y -= 10
Expand Down
22 changes: 12 additions & 10 deletions src/main/kotlin/pixi/externals/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ fun Color(string: String): Color {
val g: String
val b: String

if (hex.length == 3) {
r = hex[0].toString().repeat(2)
g = hex[1].toString().repeat(2)
b = hex[2].toString().repeat(2)
} else if (hex.length == 6) {
r = hex.substring(0, 2)
g = hex.substring(2, 4)
b = hex.substring(4, 6)
} else {
throw IllegalArgumentException("Invalid hex string: $string")
when (hex.length) {
3 -> {
r = hex[0].toString().repeat(2)
g = hex[1].toString().repeat(2)
b = hex[2].toString().repeat(2)
}
6 -> {
r = hex.substring(0, 2)
g = hex.substring(2, 4)
b = hex.substring(4, 6)
}
else -> throw IllegalArgumentException("Invalid hex string: $string")
}

return Color(r.toInt(16), g.toInt(16), b.toInt(16))
Expand Down

0 comments on commit 8656c94

Please sign in to comment.