Yay ! It’s time to make some solid stuff !

Here is one interesting feature of the LREditor : the multishape body edition. It’s using the P2 physics integrated by Phaser to add and remove shapes on a body.

In order to do that, go to the Physics tab in the Attributes panel. If you didn’t do anything yet, you should have a button “Add Body” available. Click on it to add a body to your sprite. By default, it adds a rectangular shape with the same size as your sprite :



The Body

In the physics panel, you should know have a “body” section and a “shapes” section. Let’s take a look at the first one:


With the LadybugRiders engine, collisions are managed via layers. You have to create layers and enable/disable collision between them. For example you can create a layer “player” and a layer “ground”, and tell them to collide. That way, bodies that bear the layer player will collide with bodies of “ground” type. In the same way, you can prevent two types of bodies to collide. We will see later how to actually edit these layers.

Motion State
You can choose between three motions states :
– STATIC : static bodies are immovable by other bodies and aren’t subject to gravity
– DYNAMIC : dynamic bodies are subjects to all forces in the physic world

Fixed Rotation
No matter how many forces act on the body, it won’t rotate

The angle of the body

That’s the multiplier applied to the gravity. 1 is the default. -1 will make the entity “fall” to the sky.

The mass of the body Now let’s take a look at the shapes section.

The Shapes

As I said before, you can add mutliple shaped to the body. Each one of them is editable :


Shapes have a name. When you’re coding your behaviours, you can get a shape of an entity by searching it by its name, so this is important. By default, the first shape is named “mainShape”.

The three button at the top respectively allow you to:
– rename the shape
– reset the shape
– remove the shape

A sensor shape will trigger collision messages, but won’t act a solid bodies. Every other shape in the physic world will basically go through it. ( Unity would refer this as a Trigger )

This is the offset of the shape, from the anchor of the sprite.

Finally, you can add a shape with the “Add Shape” button. Then input field allows you to name this new shape before creating it.

Some Code

We will take a look at what you have access in the code, apart from the basic stuff Phaser already provides.
As a reminder, I’ll put the two main links to the documentation on P2 body:

Phaser Body

P2 Body

What will interest us is what you can do in your Behaviour classes, right? These are the two function you can override in your behaviour :

MyBehaviour.prototype.onBeginContact =function(otherBody, myShape, otherShape, equation){

MyBehaviour.prototype.onEndContact =function(otherBodymyShape, otherShape, equation){

These are respectively called when the body attached to GameObject begins/end a collision with another body in the world ( sensors count too ). Let’s take a look at the parameters :

The other Phaser.Physics.P2.Body. Inside the LadubugRiders Engine, it contains a go property. With that you can access the GameObject – and the Entity- of the body.

This is the P2 Shape of your behaviour’s body that is actually colliding.

This is the P2 Shape of the other body that is actually colliding.

The ContactEquation of the collision. This may seem a bit complicated but you can probably use it sometimes.