ekeimaja Posted November 18, 2015 Share Posted November 18, 2015 create: function () { this.game.world.setBounds(0, 0, 1920, 120); this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.defaultRestitution = 0.8; this.player = this.game.add.sprite(100, 100, 'player_spr'); this.game.physics.p2.enable(this.player); this.game.camera.follow(this.player); this.cursors = this.game.input.keyboard.createCursorKeys(); }, update: function () { if (this.cursors.right.isDown) { this.player.body.thrust(400); } else if (this.cursors.left.isDown) { this.player.body.reverse(400); } }This code is based on tutorial code, so it should be right. But it is not working at all. Link to comment Share on other sites More sharing options...
mattstyles Posted November 18, 2015 Share Posted November 18, 2015 I dont know how Phaser implements things, but, dont you need some sort of `this.player.update()` or a world update? p2 normally has a piece of code (like this) that steps the world simulation forward. It is necessary because you are applying forces and the simulation then translates those forces into momentum, which, in turn, moves your stuff around. Stuff like collision detection normally happens in the simulation step (or update) function as well. edit: oh, I just saw the `this.game.physics.startSystem(Phaser.Physics.P2JS)` which I guess handles starting off that simulation step loop. Link to comment Share on other sites More sharing options...
pog Posted November 18, 2015 Share Posted November 18, 2015 this.game.world.setBounds(0, 0, 1920, 120);I noticed you have a small y size on your world, do you have enough room with the size of the sprite to move? Link to comment Share on other sites More sharing options...
ekeimaja Posted November 19, 2015 Author Share Posted November 19, 2015 Does it need space on y-axis, if movement is only on x-axis? Link to comment Share on other sites More sharing options...
pog Posted November 19, 2015 Share Posted November 19, 2015 I don't really know, I'm still only a phaser noob. But how tall is your sprite and where is it's anchor point? If the sprite is out of bounds it might be causing problems. Link to comment Share on other sites More sharing options...
ekeimaja Posted November 19, 2015 Author Share Posted November 19, 2015 Sprite is 30 x 30, anchor is not defined. OT: How I can limit bouncing height, so it jumps only in specific height? Now it is bouncing all the time higher and higher. Link to comment Share on other sites More sharing options...
Recommended Posts