los-cocos / cocos

graphic library for games and multimedia, for python language on PC-like hardware
http://los-cocos.github.io/cocos-site/
Other
632 stars 147 forks source link

Support for TMX animated tiles #283

Open Freakus opened 7 years ago

Freakus commented 7 years ago

As Tiled supports animated tiles, it would be nice to have this supported in cocos.

I've been trying to work on adding this to the load_tmx() function myself by stepping through the relevant tags in the tileset and building AnimationFrames which can then be compiled into an Animation at the end and stored instead of the original tile image. However, I'm getting strange behaviour as the screen moves to show and away from such tiles repeatedly; specifically the animation's frame timings are all going wrong, switching frames at irregular intervals and I suspect some frames cycling so fast you can't even see them.

Here's the modified version of load_tmx() that resulted from my efforts: load_tmx.txt You can clearly see the areas I've messed with as I've marked them with big begin/end butchery comments. (I was expecting it to be more involved than it was).

Note that whilst at it, I also threw in some code to handle map-level properties too.

Freakus commented 7 years ago

I think I've found why the animations are appearing to go wrong. It seems that _update_sprite_set() in MapLayer isn't properly cleaning up the old sprites. I'm unsure of the exact issue involved but adding"self._sprites[k].delete()" just before the del statement appears to do the job nicely.