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

2012/2/19

how to creat footprint?

aliso aliso

2012/2/19

#
Which methods can i use for that? i've already have an actor and it can walk around. can i put other images next to the actor and how to do that? The second problem is the footprint will disappear after 5 seconds.
danpost danpost

2012/2/20

#
Create an actor class called 'Footprint' and each time the walking actor takes a step, add a footprint to the world (at his feet, of course). The Footprint class can then control its life. You can make if fade by adjusting its transparency, and when its transparency reaches a certain limit, remove itself. It would be a gradual change, so you probably need a counter to control the number of act cycles before the next change. SO, basically, in the walking actors class, when a step is taken
getWorld().addObject(new Footprint(), getX(), getY() + getHeight() / 2);
and the Footprint class have instance integer variables 'final int MAX_TIME = 100;' and 'int changeTimer = MAX_TIME;'. In the Footprint act() method
changeTimer--;
if (changeTimer == 0)
{
    changeTimer = MAX_TIMER;
    setTransparency(getTransparency() - 15));
    if (getTransparency() < 50) getWorld().removeObject(this);
}
danpost danpost

2012/2/20

#
Correction (need the image):
changeTimer--;
if (changeTimer == 0)
{
    changeTimer = MAX_TIME; // not MAX_TIMER
    GreenfootImage img = getImage(); // this was missing
    img.setTransparency(img.getTransparency() - 15); // had too many ')'
    if (img.getTransparency() < 50) getWorld().removeObject(this);
    setImage(img);
}
Also, MAX_TIME should probably be around 20, not 100; but depends on your scenario speed (20 is good for medium speed; a higher number would be neccessary for higher speeds.
aliso aliso

2012/2/22

#
Thanks ! img.setTransparency is a really good code!
You need to login to post a reply.