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

1 decade ago by andrecaribe

Hi! My Problem...
Chrome returns to me:
Uncaught TypeError: Cannot call method 'SetDebugDraw' of undefined
ig.Box2DDebug.ig.Class.extend.drawdebug.js:41
ig.Box2DGame.extend.drawmain.js:60
window.ig.Class.extend.prototype.(anonymous function)impact.js:404
ig.Game.ig.Class.extend.rungame.js:154
ig.System.ig.Class.extend.runsystem.js:101
(anonymous function)

My code:
ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'impact.font',
    
    'game.entities.player',
    'game.levels.level1',
    
    'plugins.box2d.game',
    'plugins.box2d.debug'
)
.defines(function(){

MyGame = ig.Box2DGame.extend({
	
    gravity: 100,
    
	// Load a font
	font: new ig.Font( 'media/04b03.font.png' ),
    
	init: function() {
        // Debug
        this.debugDrawer = new ig.Box2DDebug( ig.world );
    
        // Keys
        ig.input.bind( ig.KEY.LEFT_ARROW, 'left' );
		ig.input.bind( ig.KEY.RIGHT_ARROW, 'right' );
        
        // Level
        this.loadLevel( LevelLevel1 );
        
        // Player
        ig.game.spawnEntity( EntityPlayer, 100, 300 );
	},
    
    loadLevel: function( data ) {
		this.parent( data );
		for( var i = 0; i < this.backgroundMaps.length; i++ ) {
			this.backgroundMaps[i].preRender = true;
		}
	},
	
	update: function() {
		this.parent();
		
        // Player
        var player = this.getEntitiesByType( EntityPlayer )[0];
        
        // Camera
		if( player ) {
			this.screen.x = player.pos.x - ig.system.width/2;
			this.screen.y = player.pos.y - ig.system.height/2 - 48;
		}
	},
	
	draw: function() {
        this.parent();
        this.debugDrawer.draw();
	}
});


ig.main( '#canvas', MyGame, 60, 512, 512, 1 );

});

What is wrong? Is a bug? How to resolve this?

1 decade ago by andrecaribe

Ok, i find...

this.debugDrawer = new ig.Box2DDebug( ig.world );

Must be after
this.loadLevel( LevelLevel1 );

to work.
Page 1 of 1
« first « previous next › last »