-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSpriteEnableHitbox.java
More file actions
44 lines (34 loc) · 1.14 KB
/
SpriteEnableHitbox.java
File metadata and controls
44 lines (34 loc) · 1.14 KB
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
package reference;
import org.openpatch.scratch.*;
import org.openpatch.scratch.extensions.recorder.*;
public class SpriteEnableHitbox {
public SpriteEnableHitbox() {
Stage myStage = new Stage(600, 240);
Sprite gamma = new Sprite("gamma", "assets/gamma_purple_badge.png");
Sprite zeta = new Sprite("zeta", "assets/zeta_green_badge.png");
gamma.setPosition(-20, 0);
zeta.setPosition(20, 0);
myStage.add(gamma);
myStage.add(zeta);
// Start with disabled hitbox
gamma.disableHitbox();
GifRecorder recorder =
new GifRecorder("examples/reference/" + this.getClass().getName() + ".gif");
recorder.start();
// Check collision with disabled hitbox
gamma.say("Touching: " + gamma.isTouchingSprite(zeta));
myStage.wait(1500);
// Enable hitbox
gamma.enableHitbox();
gamma.say("Hitbox enabled");
myStage.wait(1000);
// Check collision after enabling
gamma.say("Touching: " + gamma.isTouchingSprite(zeta));
myStage.wait(1500);
recorder.stop();
myStage.exit();
}
public static void main(String[] args) {
new SpriteEnableHitbox();
}
}