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 trigoletto

I've been playing with some box2d examples and got stuck on this error:

Uncaught TypeError: Cannot call method 'GetPosition' of null entity.js:47

Uncaught TypeError: Cannot call method 'GetPosition' of null entity.js:47
ig.Box2DEntity.ig.Entity.extend.update entity.js:47
ig.Box2DEntity.extend.update cars.js:189
(anonymous function) impact.js:448
ig.Game.ig.Class.extend.updateEntities game.js:212
ig.Game.ig.Class.extend.update game.js:189
ig.Box2DGame.ig.Game.extend.update game.js:121
(anonymous function) impact.js:448
ig.Box2DGame.extend.update main.js:68
(anonymous function) impact.js:448
ig.Game.ig.Class.extend.run game.js:170
ig.System.ig.Class.extend.run system.js:101
animate impact.js:376

The line 189 that the error log points is the this.parent() in my update function

cars.js
update: function() {
			//killOrthogonalVelocity(this.leftWheel);
			//killOrthogonalVelocity(this.rightWheel);
			//killOrthogonalVelocity(this.leftRearWheel);
			//killOrthogonalVelocity(this.rightRearWheel);
			
			// Key pressed
			if( ig.input.pressed('accelerate') ) {
				this.carBody.WakeUp();
				engineSpeed = -HORSEPOWERS;
			}
			
			if( ig.input.pressed('brake') ) {
				engineSpeed = HORSEPOWERS;
			}
			
			if( ig.input.pressed('turnleft') ) {
				steeringAngle = MAX_STEER_ANGLE
			}
			
			if( ig.input.pressed('turnright') ) {
				steeringAngle = -MAX_STEER_ANGLE
			}
			
			// Key released
			if(( ig.input.released('accelerate') ) || (ig.input.released('brake'))) {
				engineSpeed = 0;
			}
			
			if(( ig.input.released('turnleft') ) || (ig.input.released('turnright'))) {
				steeringAngle = 0;
			}
			
			this.parent();
		}

main.js
update: function() {
		// screen follows the player
		var player = this.getEntitiesByType( EntityCars )[0];

		if(player) {
			this.screen.x = player.pos.x - ig.system.width/2;
			this.screen.y = player.pos.y - ig.system.height/2;
		}
		
		// Update all entities and backgroundMaps
		this.parent();
		
	}

Any thoughts?

1 decade ago by dominic

Did you call this.parent( x, y, settings ); in your Entity's init()?

Line 47 of the box2d entity.js is
var p = this.body.GetPosition();

So, for your entity, this.body is somehow undefined. It should have been set by the init() (or createBody() to be specific).

1 decade ago by trigoletto

Just for the record, I had both functions on my code, createBody() (had the code) and init() (was empty). I just removed init() and everything went great.

Thanks dominic
Page 1 of 1
« first « previous next › last »