Matter.js is more resource intensive and should be used only if arcade physics is not an option.There are a few things to note about what we saw in this tutorial: While the focus of this tutorial was around collisions, a physic engine can be used for so much more. You just saw how to use Matter.js as the physics engine in a Phaser 3.x game. If it isn’t, we can start the explosion animation and destroy the plane when the animation ends. If the correct collision happened, we need to make sure our plane isn’t already exploding. Then we need to make sure the collision happened between a plane and an obstacle and not something else. We need to look for a collision event between two physics bodies. Tracking collisions with Matter.js is not as easy as tracking them with arcade physics. On your computer, create a new directory with an index.html file that contains the following markup: Essentially we need to add some code that was seen in other Phaser 3.x tutorials on the blog. To get us up to speed when it comes to collisions in a Phaser game, we need to add a foundation to our project. Getting Started with a Phaser 3.x Project If you want to learn how to animate a spritesheet that has an atlas file, check out my tutorial titled, Animate a Compressed Sprite Atlas in a Phaser Game. The physics body is only visible for demonstration purposes and can be hidden in a realistic scenario.įor this tutorial we’re not going to explore how to animate sprites even though some code around animation will be included. While this isn’t pixel perfect due to using polygons, it is a lot more refined than what we saw in the previous tutorial. Both sprites have a custom physics body which is fitted to the image. In the above example, we have two sprites, one of which is animated. To get an idea of what we are going to build, take a look at the following animated image: In this tutorial, we’re going to explore collisions once more in a Phaser game, but this time with Matter.js and more refined boundaries. Matter.js is another supported physics engine in Phaser 3.x and while it offers quite a bit of functionality that arcade physics doesn’t offer, it also offers custom polygon physics bodies. While you should use the arcade physics engine whenever possible, due to its speed and efficiency, sometimes working with box and circle physics bodies isn’t enough. In this previous tutorial titled, Handle Collisions Between Sprites in Phaser with Arcade Physics, the focus was around the arcade physics engine that Phaser integrates with. I recently wrote about handling collisions in a Phaser 3.x game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |