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

2016/8/11

How to pause a single actor

AuroraGamer AuroraGamer

2016/8/11

#
Hi, I'm fairly new to this, so go easy on me! I'm trying to health bar that decreases at certain time intervals, I'm trying to just use setImage to change the image of the health bar, (I have 15 images), but if I use Greenfoot.delay that pauses the entire game, which won't work, so how would I delay just the health bar?
danpost danpost

2016/8/11

#
Start your counter at 15 (the number of images) times the number of act cycles to retain one image (in a normal speed scenario, 55 act cycles is about one second). The following example uses 4 seconds (approximately) per image:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// instance field
private int health = 15 * 220;
 
// in act method
health--;
if (health % 220 == 0)
{
    updateHealth(health / 220);
    if (health == 0)
    {
        // do whatever when health is gone
    }
}
 
// method to update health bar
public void updateHealth(int howMuch)
{
    // update health bar ('howMuch' will have a value between 0 and 14, decreasing each time)
}
AuroraGamer AuroraGamer

2016/8/12

#
Thanks, that worked
You need to login to post a reply.