below is my code, but the "die" animation just won't appear!
ig.module(
'game.entities.cutie'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityCutie = ig.Entity.extend({
size: {x:32, y:32},
type: ig.Entity.TYPE.A, // Player friendly group
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
animSheet: new ig.AnimationSheet( 'media/cutie.png', 32, 32),
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idleup', 0.1, [9] );
this.addAnim( 'idledown', 0.1, [0] );
this.addAnim( 'idleleft', 0.1, [3] );
this.addAnim( 'idleright', 0.1, [6] );
this.addAnim( 'up', 0.1, [9,10,11] );
this.addAnim( 'down', 0.1, [0,1,2] );
this.addAnim( 'left', 0.1, [3,4,5] );
this.addAnim( 'right', 0.1, [6,7,8] );
},
update: function() {
this.vel.x = 0;
this.vel.y = 0;
if( ig.input.state('up') ) {
this.currentAnim = this.anims.up;
this.vel.y = -100;
}
else if( ig.input.state('down') ) {
this.currentAnim = this.anims.down;
this.vel.y = 100;
}
if( ig.input.state('left') ) {
this.currentAnim = this.anims.left;
this.vel.x = -100;
}
else if( ig.input.state('right') ) {
this.currentAnim = this.anims.right;
this.vel.x = 100;
}
if( !this.vel.x && !this.vel.y ) {
// not already idle? -> set idle anim
if( !this.idle ) {
this.idle = true;
if ( this.currentAnim == this.anims.up ) {
this.currentAnim = this.anims.idleup;
}
else if (this.currentAnim == this.anims.down ) {
this.currentAnim = this.anims.idledown;
}
else if (this.currentAnim == this.anims.left ) {
this.currentAnim = this.anims.idleleft;
}
else {
this.currentAnim = this.anims.idleright;
}
}
}
else {
this.idle = false;
}
// shoot
if( ig.input.pressed('shoot') ) {
ig.game.spawnEntity( EntityFire, this.pos.x, this.pos.y, {flip:this.flip} );
}
this.parent();
}
});
EntityFire = ig.Entity.extend({
size: {x: 16, y: 16},
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.B, // Check Against B - our evil enemy group
collides: ig.Entity.COLLIDES.PASSIVE,
animSheet: new ig.AnimationSheet( 'media/fire.png', 32, 48 ),
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'idle', 0.1, [0,1,2,3,4,5,6,7,8,9,10,11] );
}
});
EntityDie = ig.Entity.extend({
size: {x: 32, y: 32},
type: ig.Entity.TYPE.NONE,
checkAgainst: ig.Entity.TYPE.B, // Check Against B - our evil enemy group
collides: ig.Entity.COLLIDES.PASSIVE,
animSheet: new ig.AnimationSheet( 'media/die.png', 32, 32 ),
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'die', 0.1, [0,1,2] );
},
update: function() {
// Check if this entity is currently playing the 'die' animation
if( this.currentAnim == this.anims.die ) {
// Has the animation completely run through? -> kill it
if( this.currentAnim.loopCount ) {
this.kill();
}
return;
}
// Otherwise update as normal, check for keys etc.
this.parent();
},
check: function( other ) {
// Don't call this.kill() here, but instead, just set
// the 'die' animation:
other.receiveDamage( 10, this );
this.currentAnim = this.anims.die.rewind();
}
});
});