Add: chain animation
This commit is contained in:
@@ -4,8 +4,8 @@ class Alien extends Phaser.Sprite {
|
||||
super();
|
||||
|
||||
this.isActivated = false;
|
||||
this.isOnstage = false;
|
||||
this.speedGrowing = Alien.DEFAULT_SPEED_SEC;
|
||||
this.tweenScale = null;
|
||||
|
||||
this.initialX = initialX;
|
||||
this.initialY = initialY;
|
||||
@@ -15,7 +15,9 @@ class Alien extends Phaser.Sprite {
|
||||
|
||||
Phaser.Sprite.call(this, game, this.initialX, this.initialY, 'alien_normal');
|
||||
this.anchor.set(0.5);
|
||||
this.scale.set(Alien.MAX_SCALE);
|
||||
// this.scale.set(Alien.MAX_SCALE);
|
||||
this.setOnInitialPosition();
|
||||
|
||||
|
||||
this.inputEnabled = true;
|
||||
this.events.onInputOut.add(this.onOut, this);
|
||||
@@ -28,24 +30,18 @@ class Alien extends Phaser.Sprite {
|
||||
onOut() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
// console.log("onOut");
|
||||
}
|
||||
|
||||
onOver() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
// console.log("onOver");
|
||||
}
|
||||
|
||||
onDown() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
// console.log("onDown");
|
||||
|
||||
if(this.onFiredFunction)
|
||||
if(typeof this.onFiredFunction !== "undefined")
|
||||
this.onFiredFunction(this);
|
||||
}
|
||||
|
||||
@@ -60,8 +56,13 @@ class Alien extends Phaser.Sprite {
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
if(!this.tweenScale) {
|
||||
this.tweenScale.stop();
|
||||
if(typeof this.tweenScaleUp !== "undefined") {
|
||||
this.tweenScaleUp.stop();
|
||||
this.tweenScaleUp = null;
|
||||
}
|
||||
if(typeof this.tweenScaleDown !== "undefined") {
|
||||
this.tweenScaleDown.stop();
|
||||
this.tweenScaleDown = null;
|
||||
}
|
||||
|
||||
this.scale.set(0);
|
||||
@@ -73,7 +74,8 @@ class Alien extends Phaser.Sprite {
|
||||
this.scale.set(Alien.MAX_SCALE);
|
||||
}
|
||||
|
||||
moveOnStage() {
|
||||
goOnstage() {
|
||||
// set random position
|
||||
let SPAWN_BOX_LEFT = 100;
|
||||
let SPAWN_BOX_WIDTH = game.world.width - 200;
|
||||
let SPAWN_BOX_TOP = 300;
|
||||
@@ -81,11 +83,28 @@ class Alien extends Phaser.Sprite {
|
||||
|
||||
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
||||
this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT;
|
||||
|
||||
// start scale tween animation
|
||||
this.shutdown();
|
||||
|
||||
this.tweenScaleUp = game.add.tween(this.scale)
|
||||
.to( { x: Alien.MAX_SCALE, y: Alien.MAX_SCALE }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
this.tweenScaleDown = game.add.tween(this.scale)
|
||||
.to( { x: 0, y: 0 }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
this.tweenScaleUp.chain(this.tweenScaleDown);
|
||||
this.tweenScaleDown.onComplete.addOnce(this.onEscaped, this);
|
||||
this.tweenScaleUp.start();
|
||||
}
|
||||
|
||||
onEscaped() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
if(typeof this.onEscapedFunction !== "undefined")
|
||||
this.onEscapedFunction(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Alien.DEFAULT_SPEED_SEC = 1000;
|
||||
Alien.DEFAULT_SPEED_SEC = 3000;
|
||||
Alien.MAX_SCALE = 3;
|
||||
|
||||
|
||||
@@ -24,18 +24,7 @@ class Game {
|
||||
this.onAlienFired, this.onAlienEscaped
|
||||
);
|
||||
alien.setActive(true);
|
||||
alien.moveOnStage();
|
||||
/*
|
||||
let alien = game.add.sprite(this.game.world.width / 2, this.game.world.height / 2, 'alien_normal');
|
||||
alien.anchor.set(0.5);
|
||||
alien.scale.set(0);
|
||||
|
||||
let alienTween = game.add.tween(alien.scale);
|
||||
// alienTween.to( { x: 4, y: 4 }, 1000, Phaser.Easing.Linear.None, true, 0, -1, true);
|
||||
// alienTween.yoyo(true, 3000);
|
||||
alienTween.to( { x: 4, y: 4 }, 1000, Phaser.Easing.Linear.None, false);
|
||||
alienTween.start();
|
||||
*/
|
||||
alien.goOnstage();
|
||||
|
||||
|
||||
// bottom
|
||||
@@ -87,11 +76,12 @@ class Game {
|
||||
|
||||
onAlienFired(sprite) {
|
||||
console.log("onAlienFired");
|
||||
sprite.moveOnStage();
|
||||
sprite.goOnstage();
|
||||
}
|
||||
|
||||
onAlienEscaped(sprite) {
|
||||
console.log("onAlienEscaped");
|
||||
// sprite.goOnstage();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user