Open Bioparatus opened 5 years ago
I've added a flag in the latest release to enable/disable animations on a per-tile/object basis:
tile.enableAnimation = true
object.enableAnimation = false
Due to changes in the last release, SpriteKit actions weren't always being created for tile objects, but this should fix it.
Thanks, but I am still not sure how I actually go about changing the animation in code. How do I change the objects animation to another one inside its tileset?
Gotcha.
So you're looking for a way to manually set the tile data (ie texture/animation) for a tile object?
Yes exactly.
I have a character (tile object) with multiple animations inside a tileset that I want to be able to change between, but I don't know how I could manually change the tile data in code. Is there a way to do that right now?
There is no way to do that currently, unfortunately.
I'll roll that functionality into the next update, but it might not solve your problem as changing the tile data on an object repeatedly to animate it will likely result in a loss of performance.
You might have better luck extracting animation data directly from your tilesets and stashing them onto an AnimationComponent (or some structure you've created for game entities) for quick access. There are two ways to go about that now, the first is via the SKTilesetData.frames
property, which returns an array of simple structures containing texture & timing data, the second is to convert that data into a SpriteKit action:
// extract tile animation as a SpriteKit action
if let walkLeftData = tileset.getTileData(named: "walk-left") {
let walkLeftAction = walkLeftData.animationAction
sprite.run(walkLeftAction)
}
Personally, I've had a lot of luck setting up characters with entity/component systems with GameplayKit, using the SKTextureAtlas.preload
method to preload texture atlases...they're really efficient. Apple's demobots project has a really good example of how to do this.
I should have an update out early next week, hope that helps.
Hi, how would I go about animating a SKTileObject in code?
The animations exist within the object's tileset, but the object is not animated to begin with.
Do I manually need to create SKActions or do I change the tileData ID somehow?