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

2013/7/5

delay sequence of content

davemib123 davemib123

2013/7/5

#
I have this content:
 public void thankYou()
    {
        getWorld().addObject(new BgItem(14), 455, 115);
        getWorld().addObject(new BgItem(15), 610, 115); 
        getWorld().addObject(new BgItem(16), 785, 115); 
        getWorld().addObject(new BgItem(17), 432, 172);
        getWorld().addObject(new BgItem(18), 557, 172); 
        getWorld().addObject(new BgItem(19), 773, 172);
        getWorld().addObject(new BgItem(20), 410, 231); 
        getWorld().addObject(new BgItem(21), 496, 231); 
        getWorld().addObject(new BgItem(22), 673, 231);
        getWorld().addObject(new BgItem(23), 496, 287); 
    }
How do I display it one at time without using Greenfoot.delay(int)?
bourne bourne

2013/7/5

#
Do you mean for it to add the next BgItem each time thankYou() is called? Or when thankYou() is called, they all get added, one after the other given some time interval?
davemib123 davemib123

2013/7/5

#
The latter
bourne bourne

2013/7/5

#
Something like this would work: (not tested)
private final int[][] BGITEM_LOCS = { {455, 115}, {610, 115}, {785, 115}, {432, 172}, {557, 172}, {773, 172}, {410, 231}, {496, 231}, {673, 231}, {496, 287} };
private final int PAUSE = 50;
private int step = -1;

public void thankYou()
{
    step = 0;
}
public void act()
{
    if (step != -1 && step++ % PAUSE == 0)
    {
        int i = step / PAUSE;
        getWorld().addObject(new BgItem(14 + i), BGITEM_LOCS[i][0], BGITEM_LOCS[i][1]);
        if (i == BGITEM_LOCS.length - 1)
            step = -1;
    }
}
You need to login to post a reply.