Hi all 🙂!
I’m really excited about the opportunities of designing actions in the Scene/Actions Editor and having them as external resources, as displayed in the WWDC 2015 video What's New in SpriteKit. I’ve been playing around with the stuff that they’re showing, but I’ve come across a pretty glaring hurdle.
In the video they are animating a character that’s a single node, but how does it work when your character is composition of nodes (e.g. torso, legs, arms, etc.) instead of a single one?
Here’s an example:
I have a cartoony spider character that is composed of eight legs of the same leg node, a torso node and an eyes node. Overall I need the spider to have two animations: Idle and Tap. Idle will display the spider bobbing around with all eight legs wiggling at different times and it’s eyes occasionally blinking. The tap animation will include some more non-uniform complex movement.
So first of all, I’ve built the spider in a separate Character.sks file, where each component node that I intend to animate is a child of the spider parent node. That .sks file is referenced in a SKReferenceNode in GameScene, so it shows up in-game without issues. Since the Scene Editor timeline of Character.sks runs on init, I can animate the Idle animations of each element on that timeline, make them all loop indefinitely and that’ll be it. However, adding the Tap animation then becomes an issue. You can’t really animate it on the timeline of the .sks file, because it doesn’t allow states, like an action file would. And you can’t really outsource that action composition to an action file, since actions are node-specific and contain no hierarchy.
GameScene.swift
-> GameScene.sks
-> SKReferenceNode "Character"
-> Character.sks
-> SKNode "Spider"
-> SKSpriteNode "Torso"
-> ...
I feel like there must be a way to do this smarter. Being only able to animate single nodes on the timeline seems overly restrictive, though I understand why there’s no current solution, since code doesn’t allow action compositions either for multiple nodes. Currently as I see it, if the character in your crazy-cool RPG game is composed of animating elements, you in fact won’t be able to design jump, run, shoot, etc. animations as they show it in the WWDC video.
1) One solution would be to add animations (Idle, Tap) to each sub-node that is animating, and then on the Character.sks timeline you only attach the Idle ones. Then when you want to activate the Tap animations, GameScene.swift would tell the Character.sks’s children to play the Tap animation. Thing is, I don’t know how to reference the Character.sks child elements from already one SKReferenceNode.
2) Another thing I’m trying now is to create a class for Character. That way at least GameScene could tell Character to “initiate Tap animations” and then Character could access those elements to make them animate. The problem here is I don’t know how to connect the Character.sks file to the Character class. I could of course easily build the character and animate it in code, but that just completely makes the Scene Editor irrelevant.
Can anyone shine some light onto this dilemma? Thanks!