diff --git a/sample-spriteAnimation/build.gradle.kts b/sample-spriteAnimation/build.gradle.kts new file mode 100644 index 0000000..1abb3e0 --- /dev/null +++ b/sample-spriteAnimation/build.gradle.kts @@ -0,0 +1,10 @@ +import com.soywiz.korge.gradle.* + +apply() + +korge { + id = "com.soywiz.sampleSpriteAnimation" + name = "SampleSpriteAnimation" + description = "A sample using Korge and the gradle plugin" + orientation = com.soywiz.korge.gradle.Orientation.LANDSCAPE +} diff --git a/sample-spriteAnimation/src/commonMain/kotlin/Main.kt b/sample-spriteAnimation/src/commonMain/kotlin/Main.kt new file mode 100644 index 0000000..9dda752 --- /dev/null +++ b/sample-spriteAnimation/src/commonMain/kotlin/Main.kt @@ -0,0 +1,88 @@ +import com.soywiz.klock.* +import com.soywiz.korev.* +import com.soywiz.korge.* +import com.soywiz.korge.input.* +import com.soywiz.korge.view.* +import com.soywiz.korim.bitmap.* +import com.soywiz.korim.format.* +import com.soywiz.korio.file.std.* + +suspend fun main() = Korge(width = 512, height = 512) { + val spriteMap = resourcesVfs["gfx/character/character.png"].readBitmap() + + + val spriteAnimationLeft = SpriteAnimation( + spriteMap = spriteMap, + spriteWidth = 16, + spriteHeight = 32, + marginTop = 96, + marginLeft = 1, + columns = 4, + rows = 1 + ) + + val spriteAnimationRight = SpriteAnimation( + spriteMap = spriteMap, + spriteWidth = 16, + spriteHeight = 32, + marginTop = 32, + marginLeft = 1, + columns = 4, + rows = 1 + ) + + val spriteAnimationUp = SpriteAnimation( + spriteMap = spriteMap, + spriteWidth = 16, + spriteHeight = 32, + marginTop = 64, + marginLeft = 1, + columns = 4, + rows = 1 + ) + + val spriteAnimationDown = SpriteAnimation( + spriteMap = spriteMap, + spriteWidth = 16, + spriteHeight = 32, + marginTop = 0, + marginLeft = 1, + columns = 4, + rows = 1 + ) + + val player1 = Sprite(spriteAnimationDown).apply { + scale(3) + xy(100,200) + } + val player2 = Sprite(spriteAnimationDown).apply { + scale(3) + xy(100,100) + } + + addChild(player1) + addChild(player2) + + + keys { + onKeyDown{ + when (it.key){ + Key.LEFT -> {player1.playAnimation(spriteAnimationLeft); player1.x-=2 } + Key.RIGHT ->{ player1.playAnimation(spriteAnimationRight); player1.x+=2} + Key.DOWN -> {player1.playAnimation(spriteAnimationDown); player1.y+=2} + Key.UP -> {player1.playAnimation(spriteAnimationUp); player1.y-=2} + Key.A -> {player2.playAnimation(spriteAnimationLeft); player2.x-=2 } + Key.D ->{ player2.playAnimation(spriteAnimationRight); player2.x+=2} + Key.S -> {player2.playAnimation(spriteAnimationDown); player2.y+=2} + Key.W -> {player2.playAnimation(spriteAnimationUp); player2.y-=2} + Key.L -> {player1.playAnimationLooped(spriteAnimationDown, 100.milliseconds)} + Key.T -> {player1.playAnimation(spriteAnimation = spriteAnimationDown, times = 3, spriteDisplayTime = 200.milliseconds)} + Key.C -> {player1.playAnimationForDuration(1.seconds, spriteAnimationDown); player1.y-=2} + Key.ESCAPE -> {player1.stopAnimation()} + + + else -> {} + } + } + } +} diff --git a/sample-spriteAnimation/src/commonMain/resources/character.png b/sample-spriteAnimation/src/commonMain/resources/character.png new file mode 100644 index 0000000..fb3d228 Binary files /dev/null and b/sample-spriteAnimation/src/commonMain/resources/character.png differ