This site requires JavaScript, please enable it in your browser!
Greenfoot back
thepangolin
thepangolin wrote ...

2014/7/13

[u]Can i have an actor change what its image is?[/u]

thepangolin thepangolin

2014/7/13

#
I think the title sums it up...
thepangolin thepangolin

2014/7/13

#
I tried to underline the title if you're wondering about the and around it. I'm new to Greenfoot.
lordhershey lordhershey

2014/7/13

#
Yes, use the setImage() call in the actor class.
thepangolin thepangolin

2014/7/13

#
thank u
lordhershey lordhershey

2014/7/13

#
you can do something like this:
public class Player extends Actor
{

    protected static GreenfootImage[] image;

    static{
        image = new GreenfootImage[4];
        image [0] = new GreenfootImage("Helicopter1.png");
        image [1] = new GreenfootImage("Helicopter3.png");
        image [2] = new GreenfootImage("Helicopter2.png");
        image [3] = new GreenfootImage("Helicopter3.png");

    }

  int counter = 0;

  public void act()
  {
    counter = (counter + 1) % image.length;

    setImage(image[counter]);
  }

}
just make sure the images are in the scenarios image directory.
You need to login to post a reply.