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

2013/3/18

how can i add a powerup

SorrelCeasar SorrelCeasar

2013/3/18

#
im trying to add a powerup that satys at the world for about 10 sec guys who can help me
danpost danpost

2013/3/18

#
Add a cycle-counter field to the powerup class and set it to about 600. An average speed scenario will run a about 60 frames per second (60 frames/second * 10 seconds = 600 frames). In the 'act' method, decrement the value of the counter and check its value for zero. If zero, remove the object.
// add this instance field to the class
private int counter = 600;

// modify (or create) your act method 
public void act()
{
    counter--;
    if (counter == 0)
    {
        getWorld().removeObject(this);
        return; // causes immediate exit from method
    }
    // the rest of your act method, if any
}
SorrelCeasar SorrelCeasar

2013/3/19

#
where will i put this in the world or in the actor that will eat or in a new class
You need to login to post a reply.