fubeca6 Posted September 9, 2014 Share Posted September 9, 2014 Good Morning, I'm trying to have my 'player' sprite be able to move 'box' sprites around the screen. So far, I can push the box... but it doesn't stop moving. The effect is like the box is on ice. I touch it and it slides away. Here's my code:function update() { game.physics.arcade.collide(player, block, moveBlock, null, this);}function moveBlock() { if (block.body.touching.up) { block.body.velocity.y = 75; } else if (block.body.touching.down) { block.body.velocity.y = -75; } else { block.body.velocity.y = 0; } if (block.body.touching.left) { block.body.velocity.x = 75; } else if (block.body.touching.right) { block.body.velocity.x = -75; } else { block.body.velocity.x = 0; }}The problem seems to be that the 'else' of the statements is never "true". Now, I put a console.log statement in the 'else' portion for vertical movement, and noticed that the only time it ever responded was when I went from pushing the block vertically to horizontally. So how I do I get the dang thing to stop moving when my player sprite is not touching it? Thanks for your help! Link to comment Share on other sites More sharing options...
lewster32 Posted September 9, 2014 Share Posted September 9, 2014 You need to set drag on the block's body - higher values will make the block come to a stop sooner, so something like 500 will make it stop pretty much immediately when the player stops pushing it:block.body.drag.setTo(500, 500);You only need to do this when creating the blocks, rather than on every update. Link to comment Share on other sites More sharing options...
fubeca6 Posted September 10, 2014 Author Share Posted September 10, 2014 Lewster32, you rock! You should write a "Phaser Pocket Reference" book - I'd buy it! Thanks Link to comment Share on other sites More sharing options...
lewster32 Posted September 10, 2014 Share Posted September 10, 2014 Haha no problem mate! I'm not in it for the money; helping people out on here has led to me learning more about Phaser than I ever could have from just working on my own projects - it certainly makes you think outside the box when tackling other people's problems. If you want to really help Phaser along I'd suggest donating to Phaser on Gittip, as it's Rich who really deserves the cash for his constant hard work on bringing such a fine framework to us all fubeca6 1 Link to comment Share on other sites More sharing options...
Recommended Posts