This page shows how to perform setup and common tasks with the PlatformerCharacterBase entity.
Adding the Platformer Entity to your project
To add the PlatformerCharacterBase to your project:
- Download the Entity from GlueVault
- Import the Entity into your project
- Create a Screen
- Add a ShapeCollection to your Screen to act as the collision for the level
- Add an instance of the PlatformerCharacterBase Entity into the Screen
- Add the following code to your Screen’s CustomActivity
// Assuming the platformer entity instance is named PlatformerCharacterBaseInstance
// Assuming the ShapeCollection is named SolidCollision
For more information on the CollideAgainst method, see this page.
Controlling the Entity
The PlatformerCharacterBase entity sets its controls to use the first Xbox360GamePad (if it is plugged in) and if not then it uses the Keyboard. If using an Xbox360GamePad you can move the entity with the left analog stick and jump with the A button. If using the keyboard you can move the entity with the left and right arrow keys and jump with the Space key.
The input code is set by assigning the PlatformerCharacterBase’s JumpInput and HorizontalInput. These properties are assigned in the entity’s CustomInitialize but they can be changed at any time.
Setting variables in Glue
PlatformerCharacterBase provides two ways of modifying the behavior of the PlatformerCharacterBase. The first is to set the various MovementValue variables on the Entity. The PlatformerCharacterBase comes with a few sets of variables which let you quickly change between varaibles.
To change variable values:
- Expand the PlatformerCharacterBase Entity.
- Click on the Variables item. You should see all modifiable variables:
- Change the GroundMovement variable from ImmediateVelocityOnGround to AccelerationOnGround:
- Change the other two values to use the corresponding “Acceleration” variables:
Now if you play the game you will see that the character uses acceleration when accelerating horizontally.
The purpose of this is not just to allow you to easily switch between two presets, but to also allow you to create additional entries in the CSV for an unlimited number of sets of coefficients.