Source code
class MyGame extends GameObject {
constructor() {
super();
/// Set auto resizeable stage
Black.stage.scaleMode = StageScaleMode.LETTERBOX;
Black.stage.setSize(500, 500);
let assets = new AssetManager();
assets.enqueueAtlas('atlas', '/assets/examples/atlas.png', '/assets/examples/atlas.json');
assets.on('complete', this.onAssetsLoaded, this);
assets.loadQueue();
}
onAssetsLoaded(m) {
this.createAnimation(250, 250);
}
createAnimation(x, y) {
var sprite = new Sprite();
sprite.blendMode = BlendMode.ADD;
sprite.x = x;
sprite.y = y;
// Get animation Texture's
// Take a look at * at the end - its wildcard! Correct numerical sorting will be applied automatically.
let textureAnim = Black.assets.getTextures('popart_pig_*');
// Add component animation controller and play animation
this.anim = sprite.addComponent(new AnimationController());
this.anim.add('anim', textureAnim, 6);
this.anim.play('anim');
sprite.alignPivot();
this.addChild(sprite);
}
}
let engine = new Engine('game-container', MyGame, CanvasDriver);
engine.start();