sprite.setPosition and sprite.body.reset

Hello, I’m new to Phaser and game development. I’m currently porting the tutorial in MDN called “2D breakout game using Phaser” to Phaser 3. I finished porting all the example application today, and then got a question related to the title “sprite.setPosition and sprite.body.reset.”

When I implemented the initial version of the lesson 16, I found that the ball in the game was placed at lower than expected to sink into the paddle a little (like the following screenshot of the lesson 15), which resulted in the unexpected collision of the ball and the paddle in lesson 16.

As I investitagted and fixed it by this commit, the cause was that I used the ball’s setPosition method instead of the ball.body’s reset method when moving the ball back to the origin. However, I failed to be sure why reset works better than setPosition here in this case. How do they differ?

The entire source code is available here:

This may be because reset() clears the body position delta. It’s almost always a good idea to use reset in these situations. You can also omit setVelocity(0) since that’s included.

1 Like

Your suggestion worked! Thanks!