package {Next step is to add the MyStarlingApp class that we used as a constructor argument for Starling. Create a new class named MyStarlingApp and make it inherit from starling.display.Sprite.
import flash.display.Sprite;
import flash.events.Event;
import starling.core.Starling;
public class Main extends Sprite {
private var _starling:Starling;
public function Main():void {
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
_starling = new Starling(MyStarlingApp, stage);
_starling.start();
}
}
}
package {All animations are referred to by the name given in Spine. For the Spineboy demo project there's two animations: "walk" and "jump".
import flash.utils.setTimeout;
import spine.animation.AnimationStateData;
import spine.starling.SkeletonAnimation;
import spine.starling.StarlingAtlasAttachmentLoader;
import spine.SkeletonData;
import spine.SkeletonJson;
import starling.core.Starling;
import starling.display.Sprite;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
public class MyStarlingApp extends Sprite {
[Embed(source="spineboy.xml",mimeType="application/octet-stream")]
static public const SpineBoyAtlasXml:Class;
[Embed(source="spineboy.png")]
static public const SpineBoyAtlasTexture:Class;
[Embed(source="spineboy.json",mimeType="application/octet-stream")]
static public const SpineBoyJson:Class;
private var _skeleton:SkeletonAnimation;
public function MyStarlingApp() {
var texture:Texture = Texture.fromBitmap(new SpineBoyAtlasTexture());
var xml:XML = XML(new SpineBoyAtlasXml());
var atlas:TextureAtlas = new TextureAtlas(texture, xml);
var attachmentLoader:StarlingAtlasAttachmentLoader = new StarlingAtlasAttachmentLoader(atlas);
var json:SkeletonJson = new SkeletonJson(attachmentLoader);
var skeletonData:SkeletonData = json.readSkeletonData(new SpineBoyJson());
var stateData:AnimationStateData = new AnimationStateData(skeletonData);
// Setup how to morph between different animation sets
stateData.setMixByName("walk", "jump", 0.3);
stateData.setMixByName("jump", "walk", 0.4);
stateData.setMixByName("jump", "jump", 0.2);
_skeleton = new SkeletonAnimation(skeletonData, false, stateData);
_skeleton.x = 400;
_skeleton.y = 460;
_skeleton.state.setAnimationByName(0, "walk", true);
setTimeout(makeJump, 3000);
addChild(_skeleton);
Starling.juggler.add(_skeleton);
}
private function makeJump():void {
_skeleton.state.setAnimationByName(0, "jump", false);
_skeleton.state.addAnimationByName(0, "walk", true, 2); // delay next animation by 2 seconds
}
}
}