1 decade ago by Rubix
Hello, as the title says I'm new to impactjs and I've already seem to hit a wall. My game loads fine until I add my entity to main.js under the .requires() section. Here is my code below.
main.js
player.js
I'm sure there's a simple solution to this, but I can't seem to find the problem in any of the tutorials I've gone through. Thanks for your help!
main.js
ig.module(
'game.main'
)
.requires(
'impact.game',
'impact.font',
'game.entities.player'
)
.defines(function(){
MyGame = ig.Game.extend({
// Load a font
font: new ig.Font('media/04b03.font.png'),
init: function() {
ig.input.bind(ig.KEY.UP_ARROW, 'up');
ig.input.bind(ig.KEY.RIGHT_ARROW, 'right');
ig.input.bind(ig.KEY.DOWN_ARROW, 'down');
ig.input.bind(ig.KEY.LEFT_ARROW, 'left');
this.spawnEntity(EntityPlayer, 50, 50);
},
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:32, y:32},
animSheet: new ig.AnimationSheet('media/Charsketchup1.png', 32, 32),
init: function( x, y, settings)
{
this.parent(x, y, settings);
this.addAnim('idle', 1, [0]);
}
update: function()
{
if( ig.input.state('up') )
{
this.y -= 5;
}
else if( ig.input.state('down') )
{
this.y += 5;
}
if( ig.input.state('right') )
{
this.x += 5;
}
else if( ig.input.state('left') )
{
this.x -= 5;
}
}
});
I'm sure there's a simple solution to this, but I can't seem to find the problem in any of the tutorials I've gone through. Thanks for your help!
