KorGE

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    How to add animated images in the game?

    Support
    2
    2
    86
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rishav Sharan
      Rishav Sharan last edited by

      I want to add an animated gif/xcf image to my game. how would I do it?

      I tried

      var animatedText: Image = image(resourcesVfs["game_title.gif"].readBitmap()) {
          dockedTo(Anchor.TOP_CENTER, ScaleMode.EXACT )
      }
      

      but that doesnt works.

      1 Reply Last reply Reply Quote 0
      • soywiz
        soywiz last edited by

        It is not straightforward. But you can read all the frames of the GIF and great a SpriteAnimation. Thought with a fixed frameTime even if the GIF has different frame times. You could also implement the animation image changing yourself manually. In the case is it enough for you to have a fixed frame time:

        import com.soywiz.korge.*
        import com.soywiz.korge.view.*
        import com.soywiz.korim.bitmap.*
        import com.soywiz.korim.color.*
        import com.soywiz.korim.format.*
        import com.soywiz.korio.file.std.*
        
        suspend fun main() = Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"]) {
        	val frames = resourcesVfs["ed3002fb3b703f38807ddb7da020169d.gif"].readBitmapImageData(GIF).frames
        	val frameTime = frames.first().time
        	val animation = SpriteAnimation(frames.map { it.bitmap.slice() }, frameTime)
        	val sprite = sprite(animation)
        	sprite.playAnimationLooped(animation)
        }
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post