korlibs / korge

KorGE Game Engine. Multiplatform Kotlin Game Engine
https://korge.org/
Other
2.57k stars 125 forks source link

Support XML and JSON spritesheets #190

Closed emign closed 4 years ago

emign commented 4 years ago

SpriteAnimations should be able to be generated with generic sprite sheet formats

examples:

XML css.zip json array.zip json Hash.zip less.zip

soywiz commented 4 years ago

Can you provide a sample file of each?

dector commented 4 years ago

There are bunch of different popular formats.

emign commented 4 years ago

added some links

soywiz commented 4 years ago

We are already supporting atlases. Maybe what we can do is to be able to construct a SpriteAnimation out of it? Since they are named and might have several animations, maybe we can provide a prefix. For example: For "RunRight01.png" we can say: construct an animation for "RunRight" with 16.milliseconds per frame. No prefix "" would grab all the textures in the atlas. Then it gets all the textures starting with RunRight, sort them, and constructs the animation. That would work for you?

emign commented 4 years ago

so you only want to support the atlas files?

soywiz commented 4 years ago

As far as I'm concerned the files you uploaded, are atlases (open those files in a text editor and compare with other atlases). I wouldn't support the CSS/LESS ones though.

.readAtlas(...).getAnimation("RunRight")
emign commented 4 years ago

okay. It was a misunderstanding. I thought you were referencing the .atlas files which are generated by phaser editor. As it turned out: phaser .atlas files are just json hash spritesheets. So the example jsonhash from the first post works. json array not, xml not.

soywiz commented 4 years ago

So in the end I have supported XML and both JSON-based (array and hash) formats. From an atlas you can get a SpriteAnimation adding a prefix or a RegExp matching the elements you want to include there.

soywiz commented 4 years ago

Documentation here: https://korlibs.soywiz.com/korge/atlas/