Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animations in code #22

Open
Bioparatus opened this issue Jan 9, 2019 · 5 comments
Open

Animations in code #22

Bioparatus opened this issue Jan 9, 2019 · 5 comments

Comments

@Bioparatus
Copy link

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?

@mfessenden
Copy link
Owner

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.

@Bioparatus
Copy link
Author

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?

@mfessenden
Copy link
Owner

Gotcha.

So you're looking for a way to manually set the tile data (ie texture/animation) for a tile object?

@Bioparatus
Copy link
Author

Bioparatus commented Jan 24, 2019

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?

@mfessenden
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants