Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

10 years 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
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!

10 years ago by dominic

You're missing a comma after your init method. Methods in Impact's class definitions are just normal object properties after all.

This missing comma should have produced a Syntax Error in your Browser. Check your Browser's Console to see these error messages.

init: function( x, y, settings)
{
	this.parent(x, y, settings);
	this.addAnim('idle', 1, [0]);
}, // <- Comma was missing!

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;
	}
}

10 years ago by Rubix

Alright I added the comma but still no dice. Here's what comes up in the console for Chrome:

Uncaught SyntaxError: Unexpected identifier player.js:20
Uncaught Unresolved (circular?) dependencies. Most likely there's a name/path mismatch for one of the listed modules:
game.main (requires: game.entities.player) impact.js:345

10 years ago by netmute

Your update method is missing a this.parent(). And the this.x and this.y calls should be this.pos.x and this.pos.y ;)

10 years ago by Rubix

Nevermind, I found the problem. I was simply missing a bracket. Thanks for your help!
Page 1 of 1
« first « previous next › last »