• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Midori Ryuu

How to efficiently manage animations and/or textures (resources) in a game? (Using Slick2D)

3 posts in this topic

Hello all.

I am using Java, particularly the Slick2D library. So far things are going well (at least I think they are). However I have stumbled into a problem.
Seeing as this is my first game, I have no idea how I should manage the Animations and the textures in the game in a way to be both memory efficient and processing efficient.

I was wondering if I should give each and every entity I have its own animations and its own textures. Currently, the way I'm doing this is by making a limited set of images, which are then shared by the animations. These images are only created once in memory.

The animations, however, are done by creating a separate and new animation for every new entity I have.

I have also created a class specifically to handle the resources.

I was wondering if this is the correct way of doing things, or is it not memory and/or performance efficient, or should the entities with similar animations share the same single animation in memory? I find this a bit inconvenient since if I want to add a frame to a particular entity's animation, then all the entities with those animations will be affected.

Or is it perhaps the other way around, and I should even make new textures for every single entity, from which I create new animations. The main reason I can think of for doing this is the effects I might want to do later on on a frame in an animation without affecting the other animations that might use this texture.

My second question is, I'm letting the resource class decide which animation it should send to an entity, depending on the state it's in. For example, it will see if the player is walking left, and give it the according animations, if he's walking right, then the right animation.

I wonder if it's more correct to let the Player class decide which animation it will request from the resource class.

This is my resource class:

package blackhorn;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public final class CAnimations {
// Player walking left
Image playerWL1;
Image playerWL2;
Image playerWL3;
Image[] playerWL;
// Player walking right
Image playerWR1;
Image playerWR2;
Image playerWR3;
Image[] playerWR;
// Player standing
Image[] playerS;
// Enemy standing
Image[] enemyS;

Image[] groundS;

Image[] bulletS;

public void init() throws SlickException {
playerWL1 = new Image("data/playerWL1.png");
playerWL2 = new Image("data/playerWL2.png");
playerWL3 = new Image("data/playerWL3.png");
playerWR1 = new Image("data/playerWR1.png");
playerWR2 = new Image("data/playerWR2.png");
playerWR3 = new Image("data/playerWR3.png");
playerS = new Image[] {new Image("data/playerS1.png")};
enemyS = new Image[] {new Image("data/enemyS1.png")};
groundS = new Image[] {new Image("data/groundS.png")};
bulletS = new Image[] {new Image("data/bulletS.png")};
playerWL = new Image[] { playerWL2, playerWL1, playerWL3, playerWL1 };
playerWR = new Image[] { playerWR2, playerWR1, playerWR3, playerWR1 };

public void getCurrentAnimation(Player player) {
player.setCurrentAnimation(new Animation(playerWL, 500));
player.setCurrentAnimation(new Animation(playerWR, 500));
else if(player.getSideSpeed()==0)
player.setCurrentAnimation(new Animation(playerS, 500));

public void getCurrentAnimation(Enemy enemy) {
enemy.setCurrentAnimation(new Animation(enemyS, 500));

public void getCurrentAnimation(Ground ground) {
ground.setCurrentAnimation(new Animation(groundS, 500));

public void getCurrentAnimation(Bullet bullet) {
bullet.setCurrentAnimation(new Animation(bulletS, 500));


And this is my player class.

public class Player extends Character {
private boolean hasFired = false;
public Player(float x, float y) {
super(x, y, 1, 1, 1, 1, 0, CConstants.ROTATION_RIGHT, CConstants.PLAYER_JUMP_SPEED, CConstants.PLAYER_WEIGHT);

public void init(GameContainer container) throws SlickException {

public void update(GameContainer container, int delta) throws SlickException {
super.update(container, delta);

public void render(GameContainer gc, Graphics g) throws SlickException {
MainGameState.animationList.getCurrentAnimation(this); //animationList is the CAnimation class instance
super.render(gc, g);

[url="https://github.com/Midori-Ryuu/Black-Horn/tree/master/Black-Horn"]The full code is on Github for those who are interested.[/url] Edited by Midori Ryuu

Share this post

Link to post
Share on other sites
I can't speak much to the Java/Slick2D specifics, but the following two patterns/idioms are the answer to your first problem.

[url="http://en.wikipedia.org/wiki/Flyweight_pattern"]Flyweight Pattern[/url]

[url="http://en.wikipedia.org/wiki/Copy-on-write"]Copy on Write[/url]

Use the flyweight pattern to easily share resources between entities, and then use copy on write so that you can "add a frame to a particular entity's animation," without effecting the other entities.

Share this post

Link to post
Share on other sites
[quote name='nox_pp' timestamp='1344956313' post='4969484']
I can't speak much to the Java/Slick2D specifics, but the following two patterns/idioms are the answer to your first problem.

[url="http://en.wikipedia.org/wiki/Flyweight_pattern"]Flyweight Pattern[/url]

[url="http://en.wikipedia.org/wiki/Copy-on-write"]Copy on Write[/url]

Use the flyweight pattern to easily share resources between entities, and then use copy on write so that you can "add a frame to a particular entity's animation," without effecting the other entities.

Thank you for the link! I had implemented (or at least think I had implemented) the Flyweight Pattern in my design, as the images are shared by the animations.

However I did not know about the Copy on Write! That will probably help me fix the animation problem I'm having.

If anyone has any other solutions, I'm always looking for insight!

And thank you again nox! :)

Share this post

Link to post
Share on other sites
Instead of loading in all those images.

try putting all relative images into a spritesheet and change the white background to the rgb color 255,0,255.

This is what i've done for my entities and player.

so I load the sprite sheet with

SpriteSheet entity = new SpriteSheet("tes/entities.png",64,64,new Color(255,0,255);
The params are the source image,the width and height of each tile, and the colour you want to act as transparent.

Then when I want to create an animation I just do something like.

Image[] entities = new Image[]{entity.getSprite(0,0),entity.getSprite(1,0)}; and so on

after that you can create the animation as normal.

It's just how I cut down loading loads of separate images. Spritesheets are not just good for animation, you can stick world tiles in them also.

Hope this helps a little bit

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0