-
Notifications
You must be signed in to change notification settings - Fork 2
Movement Animations
-
Update or create the atlas file of the character you wish to edit. To do this use a Texture packer as described in this wiki under animations. Be sure to follow the formatting of file outlined in these texture packers and read the documentation if you get stuck.
-
Add a
AnimationRederComponent()
to the entity you wish to animate. -
Add specific animations to the AnimationRedercomponent using:
animator.addAnimation(name, framerate, playMode)
. -
Add the atlas file to the GameArea's textures ie
ForestGameArea.forestTexturesAtlases = {"images/male_character"}
. This will load your sprite skin into the game environment. -
Add a
eventListener
to theAnimationController
for your component. This will trigger the animation when the event is called.
How Animations are Called For the Player
Animation trigger events will be thrown on the key release managed from KeyboardPlayerInputCompnent
:
public boolean keyUp(int keycode) {
switch (keycode) {
case Keys.W:
entity.getEvents().trigger("standUp");
return true;
case Keys.A:
entity.getEvents().trigger("standLeft");
return true;
case Keys.S:
entity.getEvents().trigger("standDown");
return true;
How Animations Are Triggered from NPC's
Movement events are thrown from PhysicsNovementComponent.movementEvents()
. private int lastDirection
stores the last compass direction taken by the entity as an integer, where north equals 0, east equals 1 etc.
It is important to check for a change in direction to prevent animations being initialized every update(). This would result in a still image because update() is called > than the animation frame rate.
public void movementEvents() {
Vector2 entityDirection = getDirection();
float x = entityDirection.x;
float y = entityDirection.y;
if (lastDirection != currentDirection) {
if (x < 0 && y < 0.5 && y > -0.5) {
entity.getEvents().trigger("walkLeft");
lastDirection = 3;
} else if (x > 0 && y < 0.5 && y > -0.5) {
entity.getEvents().trigger("walkRight");
lastDirection = 1;
} else if (x < 0.5 && x > -0.5 && y > 0) {
entity.getEvents().trigger("walkUp");
lastDirection = 0;
} else if (x < 0.5 && x > -0.5 && y < 0) {
lastDirection = 2;
entity.getEvents().trigger("walkDown");
}
}
Entities and Components
Interaction System
Unit Testing
Input Handling
UI
Game Screens and Areas
Map Generation
Basic Interactable Objects Design