I am trying to animate, that if my enemy is moving to the right it plays the first gif and if he walks to the left an other gif...
Here is my Enemy Code (all you need I think):
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Enemy1 here. * * @author (your name) * @version (a version number or a date) */ public class Enemy1 extends Enemy { private int speed = -3; private int count = 0; private int health = 1; private int vSpeed = 0; private int accel = 1; boolean hitByProjectile = false; private int animationCounter = 0; private int frame = 1; private GreenfootImage run1 = new GreenfootImage("Enemy1left.png"); private GreenfootImage run2 = new GreenfootImage("Enemy2left.png"); private GreenfootImage run3 = new GreenfootImage("Enemy3left.png"); GifImage myGif = new GifImage ("Enemy1_gif.gif"); GifImage myGif2 = new GifImage ("Enemy1_gif2.gif"); /** * Act - do whatever the Enemy1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { count++; moveAround(); hitByProjectile(); animationCounter ++; } public void moveAround() { if(count < 120) { setLocation(getX() + speed,getY()); } else { speed = - speed; count = 0; } }