For todays post on phaser ce I thought I would play around with acceleration. Doing so with phaser ce is just a matter of setting point values for the instance of Phaser.Point at Sprite.body.acceleration in a physics enabled Sprite. In this post I will be covering a simple silly use case example of how to go about working with acceleration in phaser ce, and also touch base on some other important tools available in the framework for doing so.
In this post I am using phaser community edition 2.11.1 of phaser.
In this example I am changing acceleration of a ball based on the distance and angle to another point of reference at the center of the game world. So in the post on top of using the Phaser.Point instance at Sprite.body.acceleration, I am also using Point methods like Point.angle, and Point.distance as well. This does not aim to be a practical example, just an exercise. In game projects acceleration is something that might be set with user input, or hitting a power up of some kind. In any case it will involve setting values at the Point instance at Sprite.body.acceleration.
Here is the method that is used to update acceleration on each frame tick.
In the method I create the ball sprite, and enable physics for the sprite.
Here I am creating a simple sprite sheet to be used to skin the sprite with.
Now that I have everything worked out I just need to get it all working with a Phaser.Game instance, and a single state object. I call my CreateBallSheet, and createBall methods in the create method of a state object to set things up. In addition I of course call my updateAccleration method in the update method as well.
Acceleration is one of many other factors to take into account when starting to play with physics in phaser ce. As I work on expanding and improving my content on phaser I will likely want to expand more on this post on a later date, and provide at least one more example involving acceleration in phaser ce. If you have any suggestions for an additional example, let me know in the comments, and that you for reading.