1 decade ago by jch02140
I have managed to get the game running and control functioning without problem... However, for some reason when the character moves, it still plays the "idle" animation...
Not sure where is the problem...
The sample can be accessed here
main.js
player.js
Not sure where is the problem...
The sample can be accessed here
main.js
ig.module(
'game.main'
)
.requires(
'impact.game',
'impact.font',
'game.entities.player',
'game.levels.test'
)
.defines(function(){
MyGame = ig.Game.extend({
gravity: 100,
// Load a font
font: new ig.Font( 'media/04b03.font.png' ),
init: function() {
// Bind keys
ig.input.bind( ig.KEY.LEFT_ARROW, 'left' );
ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' );
ig.input.bind( ig.KEY.X, 'jump' );
// Load Level
this.loadLevel(LevelTest);
},
update: function() {
// Update all entities and backgroundMaps
this.parent();
// Add your own, additional update code here
},
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
// Add your own drawing code here
var x = ig.system.width/2,
y = ig.system.height/2;
this.font.draw( 'It Works!', x, y, ig.Font.ALIGN.CENTER );
}
});
// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 320, 240, 2 );
});
player.js
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
size: {x: 40, y: 88},
offset: {x: 17, y: 10},
maxVel: {x: 100, y: 150},
friction: {x: 600, y: 0},
flip: false,
animSheet: new ig.AnimationSheet( 'media/player.png', 75, 100 ),
accelGround: 1200,
accelAir: 600,
jump: 300,
init: function( x, y, settings ) {
this.parent( x, y, settings );
// Add the animations
this.addAnim( 'idle', 1, [15,15,15,15,15,14] );
this.addAnim( 'run', 0.07, [4,5,11,0,1,2,7,8,9,3] );
this.addAnim( 'jump', 1, [13] );
this.addAnim( 'fall', 0.4, [13,12], true ); // stop at the last frame
//this.addAnim( 'pain', 0.3, [6], true );
ig.game.player = this;
},
update: function(){
// Handle user input; move left or right
var accel = this.standing ? this.accelGround : this.accelAir;
if( ig.input.state('left') ) {
this.accel.x = -accel;
this.flip = true;
}
else if( ig.input.state('right') ) {
this.accel.x = accel;
this.flip = false;
}
else {
this.accel.x = 0;
}
// jump
if( this.standing && ig.input.pressed('jump') ) {
this.vel.y = -this.jump;
//this.sfxJump.play();
}
this.currentAnim.flip.x = this.flip;
this.parent();
}
});
});
