MarrMooMoo Posted September 18, 2017 Share Posted September 18, 2017 I'm still new to Phaser and coding in general so I apologize if this doesn't make sense. I have player gravity and bounce set to 0 and movement velocity cranked up so movement seems instant. I'm looking to make it so that once the player hits a certain point on the x axis it stops, then the movement key must be pressed again to continue in either direction until it hits another one of those points, and so on. One idea I had was to populate the screen with vertical immovable bars with collision spread out evenly, but I don't know how to make it so that once the player hits them and stops their momentum they can then proceed through them at the press of the movement key (or if thats even possible). I feel like its more likely that I'd be able to set a coordinate for movement to stop, but again I don't know if thats possible either. Any help would be appreciated! Link to comment Share on other sites More sharing options...
MarrMooMoo Posted September 18, 2017 Author Share Posted September 18, 2017 I think I might've found my solution with moveToXY, but if anyone has better suggestions for what I'm describing please tell me! Link to comment Share on other sites More sharing options...
samid737 Posted September 19, 2017 Share Posted September 19, 2017 You can add the points to an array and iterate trough the array in update. To make the player move again you can use input events: var Xcoordinates=[100,200,340]; var offset=5; var movementKey; function create() { movementKey=game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); movementKey.onDown.add(walk, game); } function update() { Xcoordinates.forEach(function(xcoord) { if((player.x>(xcoord-offset))&&(player.x<xcoord+offset)) { player.body.velocity.x=0; } }; } function walk() { player.body.velocity.x=200; } input event example: For the vertical bars approach you can use arcade physics and resize the physics body using either sprite scaling or setSize. Then use game.physics.arcade.overlap() to check for overlaps. Again you can use input events to move the object once is has come to a stop. Link to comment Share on other sites More sharing options...
Recommended Posts