As the subject says, I have a sprite I’ve added to the world. I have keys set up to apply force to the object, so I can move it around. What do I have to do to stop the object from leaving the world?
Existing code
Game.create = function(){
this.cameras.main.useBounds = false;
this.matter.world.setBounds(
Game.config.game.world.width/2,
Game.config.game.world.height/2,
Game.config.game.world.width,
Game.config.game.world.height
);
Game.Player = this.matter.add.sprite(
Game.config.game.width/2,
Game.config.game.height/2,
'ship-atlas',
'ship.png'
);
Game.Player.setFriction(0,0,0);
// I thought this would do it, but all it does is generate an error
// "Cannot read property 'x' of undefined
this.matter.add.worldConstraint(Game.Player.body, 1, 0.2);
this.cameras.main.startFollow(Game.Player);
Game.cursors = this.input.keyboard.createCursorKeys();
};
Game
is just a generic object I’ve created to store all the game data, as I hate adding stuff globally.