LibGDX – Simple action replay

I have been working on a “2D platformer” and while there are lots of basic features to finish I fancied something a it fun. The first time I saw a replay of gameplay was probably “Striker” or “Speedball 2” on the Amiga 500, I should imagine it was quite difficult back then. Memory not being an issue now I thought it would be simple enough to implement.

Featured image

Action Replay System
frames are the key to animation, so I would capture enough information at each tick and store it in an array of frames. The hero co-ordinates and current texture would be needed along with the current time. I already have a timer class which works as a basic stop watch.


public class Frame {
public float x;
public float y;
public TextureRegion frame;
public float time;
public float delta;
public int frame_rate;

public Frame(float x, float y, float time, float delta, int fps, TextureRegion frame){
this.x = x;
this.y = y;
this.time = time;
this.delta = delta;
this.frame_rate = fps;
this.frame = frame;
}
}

Replay Class
This class contains the array of frames which you add too every tick of your game. I have conditions to adding a new frame like… “if timer.running”, when I hit the goal hitbox the timer stops and frames are no longer added to the array.

I then have a simple if replay is true test then call the tick and draw methods of this class. Tick will push the frame onto the next in the array until it reaches the last frame and draw will output the hero, a tooltip and the current time to the screen.


public class Replay {
public Frame current_frame;
public float playback_frame = 0;
public Array frames = new Array();
BitmapFont font = new BitmapFont();
main game;
public Replay(main game){
font.setScale(.6f);
this.game = game;
}
public void tick(float delta){
if(playback_frame < frames.size){
current_frame = frames.get((int) playback_frame);
}
playback_frame ++;
}
public void draw(float delta, SpriteBatch batch){
if(current_frame != null){
batch.draw(current_frame.frame, current_frame.x-5, current_frame.y-5);
batch.draw(game.media.tooltip, current_frame.x-11, current_frame.y+24);
font.draw(batch, "Time: " + String.format("%.2f", current_frame.time), current_frame.x-10, current_frame.y+42);
}
}
public void add_frame(Frame frame){
frames.add(frame);
}
public void reset(){
playback_frame = 0;
frames.clear();
}
}

This is a quick and dirty implementation, I will re-factor the code later. There are hard coded values and textures passed in from the main class and so on, also currently I do not check the FPS for capture and playback, I assume LibGDX always runs at 60fps.

Advertisements

#pixel_dailies – my first week

Pixel Dailies is a twitter account that posts a new theme every 24 hours, a great way to practice making quick pixel art.

“Come and pixel art with us. Themes tweeted daily! Tag with  and . Run by +. More info at

I have started taking part this week and so far enjoyed it, first day saw “Fire” as he keyword. I decided to make FlameBo, a World Industries character that appeared on skateboards.

“Horn” was the next theme, I considered a Rhino or Unicorn until a friend mentioned Adventure Time’s Rainicorn! My line art was not too bad but the colours I chose were just awful. I came across a nice Rainicorn on deviant art and used its colour palette:


“Orion Trail” a recent kickstarter project was next, its close to its goal and worth a look! I used art work from the project page as inspiration and added Moonman for a bit of fun:

I intend on doing as many as I can to improve my pixel skills and maybe add some animation to a few as well.