Impact and Node.js Video #3
Posted: Fri Mar 09, 2012 4:59 pm
Congrats!hallsofvallhalla wrote:1200 views over the weekend!!!!
Code: Select all
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
animSheet: new ig.AnimationSheet( 'media/player.png', 32, 48 ),
size: {x: 32, y: 48},
type: ig.Entity.TYPE.A,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
speed:100,
init: function( x, y, settings ) {
this.parent( x, y, settings );
this.addAnim( 'up', .21, [12,13,14,15] );
this.addAnim( 'down', .21, [0,1,2,3] );
this.addAnim( 'left', .21, [4,5,6,7] );
this.addAnim( 'right', .21, [8,9,10,11] );
this.addAnim( 'idleup', .1, [14] );
this.addAnim( 'idledown', .1, [2] );
this.addAnim( 'idleleft', .1, [6] );
this.addAnim( 'idleright', .1, [10] );
this.currentAnim = this.anims.idledown;
},
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();
}
});
});
Figured out the animation problem. Still having a problem with certain sprites moving diagonally though.MikeD wrote:Congrats!hallsofvallhalla wrote:1200 views over the weekend!!!!
Having a little trouble here...Finally had a little time to actually do the tuts.
The player is moving around, but if you hit right/left then up/down he will move diagonally and the animation isn't working, coming up with no errors so I'm not exactly sure what's wrong with it...
player.png is 4x4 with a size of 32 width and 48 height
Here's player.js
Code: Select all
ig.module( 'game.entities.player' ) .requires( 'impact.entity' ) .defines(function(){ EntityPlayer = ig.Entity.extend({ animSheet: new ig.AnimationSheet( 'media/player.png', 32, 48 ), size: {x: 32, y: 48}, type: ig.Entity.TYPE.A, checkAgainst: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.PASSIVE, speed:100, init: function( x, y, settings ) { this.parent( x, y, settings ); this.addAnim( 'up', .21, [12,13,14,15] ); this.addAnim( 'down', .21, [0,1,2,3] ); this.addAnim( 'left', .21, [4,5,6,7] ); this.addAnim( 'right', .21, [8,9,10,11] ); this.addAnim( 'idleup', .1, [14] ); this.addAnim( 'idledown', .1, [2] ); this.addAnim( 'idleleft', .1, [6] ); this.addAnim( 'idleright', .1, [10] ); this.currentAnim = this.anims.idledown; }, 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(); } }); });
Code: Select all
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
size: {x: 32, y: 48},
type: ig.Entity.TYPE.A,
checkAgainst: ig.Entity.TYPE.NONE,
collides: ig.Entity.COLLIDES.PASSIVE,
speed:100,
animSheet: new ig.AnimationSheet( 'media/player.png', 32, 48 ),
init: function( x, y, settings ) {
this.parent( x, y, settings );
// Add the animations
this.addAnim( 'up', .1, [40,41,42,43,44,45,46,47,48,49] );
this.addAnim( 'down', .1, [0,1,2,3,4,5,6,7,8,9] );
this.addAnim( 'left', .1, [60,61,62,63,64,65,66,67,68,69] );
this.addAnim( 'right', .1, [20,21,22,23,24,25,26,27,28,29] );
this.addAnim( 'upleft', .1, [50,51,52,53,54,55,56,57,58,59] );
this.addAnim( 'upright', .1, [30,31,32,33,34,35,36,37,38,39] );
this.addAnim( 'downleft', .1, [70,71,72,73,74,75,76,77,78,79] );
this.addAnim( 'downright', .1, [10,11,12,13,14,15,16,17,18,19] );
this.addAnim( 'idleup', .1, [40] );
this.addAnim( 'idledown', .1, [0] );
this.addAnim( 'idleleft', .1, [60] );
this.addAnim( 'idleright', .1, [20] );
this.addAnim( 'idleupleft', .1, [50] );
this.addAnim( 'idleupright', .1, [30] );
this.addAnim( 'idledownleft', .1, [70] );
this.addAnim( 'idledownright', .1, [10] );
this.currentAnim = this.anims.idleup;
},
update: function() {
// Movement
if( ig.input.state('left') && ismove != 3) {
if( ig.input.state('up')) {
this.currentAnim = this.anims.upleft;
} else if( ig.input.state('down')) {
this.currentAnim = this.anims.downleft;
} else {
this.currentAnim = this.anims.left;
ismove = 7;
}
} else if( ig.input.state('right') && ismove != 7) {
if( ig.input.state('up')) {
this.currentAnim = this.anims.upright;
} else if( ig.input.state('down')) {
this.currentAnim = this.anims.downright;
} else {
this.currentAnim = this.anims.right;
ismove = 3;
}
} else if( ig.input.state('down') && ismove != 1) {
if( ig.input.state('left')) {
this.currentAnim = this.anims.downleft;
} else if( ig.input.state('right')) {
this.currentAnim = this.anims.downright;
} else {
this.currentAnim = this.anims.down;
ismove = 5;
}
} else if( ig.input.state('up') && ismove != 5) {
if( ig.input.state('left')) {
this.currentAnim = this.anims.upleft;
} else if( ig.input.state('right')) {
this.currentAnim = this.anims.upright;
} else {
this.currentAnim = this.anims.up;
ismove = 1;
}
} else {
this.vel.x = 0;
this.vel.y = 0;
ismove = 0;
if( this.direction == 1 ) {
this.currentAnim = this.anims.idleup;
}
if( this.direction == 2 ) {
this.currentAnim = this.anims.idleupright;
}
if( this.direction == 3 ) {
this.currentAnim = this.anims.idleright;
}
if( this.direction == 4 ) {
this.currentAnim = this.anims.idledownright;
}
if( this.direction == 5 ) {
this.currentAnim = this.anims.idledown;
}
if( this.direction == 6 ) {
this.currentAnim = this.anims.idledownleft;
}
if( this.direction == 7 ) {
this.currentAnim = this.anims.idleleft;
}
if( this.direction == 8 ) {
this.currentAnim = this.anims.idleupleft;
}
}
if ( this.currentAnim == this.anims.up) {
this.vel.x = 0;
this.vel.y = -this.speed;
this.direction = 1;
}
if ( this.currentAnim == this.anims.upright) {
this.vel.x = +this.speed;
this.vel.y = -this.speed;
this.direction = 2;
}
if ( this.currentAnim == this.anims.right) {
this.vel.x = +this.speed;
this.vel.y = 0;
this.direction = 3;
}
if ( this.currentAnim == this.anims.downright) {
this.vel.x = +this.speed;
this.vel.y = +this.speed;
this.direction = 4;
}
if ( this.currentAnim == this.anims.down) {
this.vel.x = 0;
this.vel.y = +this.speed;
this.direction = 5;
}
if ( this.currentAnim == this.anims.downleft) {
this.vel.x = -this.speed;
this.vel.y = +this.speed;
this.direction = 6;
}
if ( this.currentAnim == this.anims.left) {
this.vel.x = -this.speed;
this.vel.y = 0;
this.direction = 7;
}
if ( this.currentAnim == this.anims.upleft) {
this.vel.x = -this.speed;
this.vel.y = -this.speed;
this.direction = 8;
}
////////////////////////////////
this.parent();
}
});
})