The is my code Player.js:
Code: Select all
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
animSheet: new ig.AnimationSheet( 'media/character.png', 32, 62 ),
size: {x: 32, y: 62},
type: ig.Entity.TYPE.A,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
speed:80,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'up', .1, [6,7,8]);
this.addAnim( 'down', .1, [0,1,2]);
this.addAnim( 'left', .1, [9,10,11] );
this.addAnim( 'right', .1, [11,12,13] );
this.addAnim( 'idleup', .1, [8] );
this.addAnim( 'idledown', .1, [0] );
this.addAnim( 'idleleft', .1, [5] );
this.addAnim( 'idleright', .1, [11] );
this.currentAnim = this.anims.idleup;
},
update: function() {
//Move Left Or Right
if ( ig.input.state('left') && ismove != 2 && ismove != 3 && ismove != 4 ) {
this.vel.x = -this.speed;
var ismove = 1;
this.direction = 1;
this.currentAnim = this.anims.left;
}else if ( ig.input.state('right') && ismove != 1 && ismove != 3 && ismove != 4 ) {
this.vel.x = +this.speed;
var ismove = 2;
this.direction = 2;
this.currentAnim = this.anims.right;
}else if ( ig.input.state('up') && ismove != 1 && ismove != 2 && ismove != 4 ){
this.vel.y = -this.speed;
var ismove = 3;
this.direction = 3;
this.currentAnim = this.anims.up;
}else if ( ig.input.state('down') && ismove != 1 && ismove != 2 && ismove != 3 ){
this.vel.y = +this.speed;
var ismove = 4;
this.direction = 4;
this.currentAnim = this.anims.down;
}else{
this.vel.x = 0;
this.vel.y = 0;
var ismove = 0;
}
/////
if ( this.direction == 1 ){
this.currentAnim = this.anims.idleleft;
}else if ( this.direction == 2 ){
this.currentAnim = this.anims.idleright;
}else if ( this.direction == 3 ){
this.currentAnim = this.anims.idleup;
}else{
this.currentAnim = this.anims.idledown;
}
this.parent();
}
});
});