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