Create the player object, set the sprite, set the physics collision shape, and set the physics properties. Place the character object in the room.
- [Instructor] Now let's get down to business and create our player object. I'll go to the objects folder and create a new group. I'll call this group "player." And in that group, we'll create a new object. I'll call it "O_player." And for an initial setting, we'll set the sprite to the idle sprite. I'll click the sprite drop down, go to player, and select s player idol. Let's check the uses physics box and set the collision shape for our new object.
I'll select the box because this will get us close enough to the sprite shape to accurately detect collisions. Let's modify the collision shape and set the fixture close to the center of the knight. There's a bit of an art to setting the collision shape to your sprite. You don't want it to be too aggressive and detect collisions when they don't seem appropriate. You also don't want to be too conservative and not detect collisions when they should happen. What we have here should be pretty close and work well for our game. We can always adjust it later if we need to.
I'll click okay. And now let's add some collision events. I'll click the add event button, select collision, and we first wanna collide with any static objects. So I'll select the static parent, go to the control tab, and drag in a comment just like we did previously. We also wanna make sure our player collides with dynamic objects. So I'll add event, select collision, parents, and p_dynamic.
Let's drag a comment in there as well. You may be wondering why we don't set the parent object for the player to the dynamic object. And I'm simply doing this cause I don't automatically wanna destroy the player object when it goes outside the room. The player's a bit of a special object, so we'll treat it as such. Let's close this out and place the player and four objects in the room to test the new collisions. I'll open up the room, go to the objects tab, select the objects dropdown, and then tiles, we'll select the floor object.
I'll zoom out a bit, and place the floor in the bottom left of the room. The nice thing about the room editor is we can change the shape of the objects within it. So, I'll grab the node on the corner of the floor and drag it out. The physics fixture will adjust itself automatically so we don't have to worry about that at all. Next let's place in our player. I'll select the drop down, go to player, and select the player object. But I'll put the player in the top corner, that way we can see the player fall and collide with the floor. Let's close out the room editor and run our game by clicking the green arrow.
You can see the player fall through the air, being affected by gravity and collide successfully with our floor.
- Setting up basic game components
- Creating the player object
- Using Finite State Machines
- Making the player duck
- Creating physics fixtures in code
- Creating physics obstacles
- Box2D liquid physics
- Creating particles that behave like water
- Creating a floating blocks obstacle
- Creating a swinging chain obstacle and a rope bridge
- Adding the finishing touches