Adding Ice and Water
Last updated
Last updated
This tutorial shows how to add ice and water collision. We'll be setting up the TileShapeCollections for these two types of tiles, and creating collision relationships to control the interaction between the Player and these tiles.
As shown in the previous tutorial, the Player already collides with the solid collision. This is automatically added by the New Project Wizard, so we don't have to do any setup for ground collision. We'll add ice collision first. To do this:
Click GameScreen
Select the Quick Actions tab and click the Add Object to Game Screen button
Select TileShapeCollection
Enter the name IceCollision
Click OK
Select the newly-created IceCollision object
Click the TileShapeCollection Properties tab
Click the From Type option
Change the Source TMX File/Object to Map
Change the Type to IceCollision
We'll repeat the process above to create water collision:
Click GameScreen
Select the Quick Actions tab and click the Add Object to Game Screen button
Select TileShapeCollection
Enter the name WaterCollision
Click OK
Select the newly-created WaterCollision object
Click the TileShapeCollection Properties tab
Click the From Type option
Change the Source TMX File/Object to Map
Change the Type to Water
Now our game has two new collision relationships: IceCollision and WaterCollision. This means that when our game runs, collision shapes are created based on the water and ice tiles, but we haven't yet told the game how to handle collisions between the Player and these collision relationships. First, we'll set up collisions between the Player and IceCollision:
Drag+drop PlayerList onto IceCollision
The newly-created PlayerVsIceCollision is automatically set up to use Platformer Solid Collision physics, so we don't need to make any changes. We also need to create collision between PlayerList and WaterCollision, but this time we need to disable Platformer Solid Collision since the Player should be able to fall into the water. To do this, drag+drop PlayerList onto WaterCollision and select No Physics.
Now if we run our game we can collide with the ice tiles and fall through water.
Now our game has ice and water TileShapeCollections and collision relationships. You may have noticed that the ice currently acts identical to solid collision (bricks). The next tutorial will create new platformer variables for moving on ice and swimming in water, and will switch between them in response to collision.