-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPauseResumeButton.java
More file actions
46 lines (40 loc) · 1022 Bytes
/
Copy pathPauseResumeButton.java
File metadata and controls
46 lines (40 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* A special button that is used either to pause or to resume the game.
*/
public class PauseResumeButton extends Button {
public static final String RESUME_BUTTON_IMAGE_NAME = "resume-button.png";
public static final String PAUSE_BUTTON_IMAGE_NAME = "pause-button.png";
public PauseResumeButton() {
super(RESUME_BUTTON_IMAGE_NAME, PAUSE_BUTTON_IMAGE_NAME);
}
@Override
protected void clickAction() {
pauseResumeToggle();
}
/**
* Sets the correct image for pausing or resuming.
*/
public void updatePauseResumeButton() {
if(getWorld().isPaused()) {
setImage(getIdleImage());
setActive(false);
} else {
setImage(getActiveImage());
setActive(true);
}
}
/**
* Pauses or resumes the game when pressing the button
*/
public void pauseResumeToggle() {
GameWorld world = getWorld();
if(isActive()) { // pause game
world.pause();
setImage(getIdleImage());
} else { // resume game
world.resume();
setImage(getActiveImage());
}
setActive(!isActive());
}
}