-
Notifications
You must be signed in to change notification settings - Fork 1
/
StartButton.java
40 lines (36 loc) · 1.01 KB
/
StartButton.java
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Start button class
* Create a button to play the game
*
* @author github.com/fiekzz
* @version 4 June 2022
*/
public class StartButton extends Actor
{
// get button asset
GreenfootImage btn = new GreenfootImage("./assets/buttons/new_start.png");
// assets
GreenfootSound theme;
GreenfootSound btnSound = new GreenfootSound("./assets/sounds/button.wav");
// button constructor
public StartButton(GreenfootSound theme)
{
// scale the button size
btn.scale(300, 300);
setImage(btn);
// set the theme
this.theme = theme;
}
public void act()
{
// check is the button has been clicked
// change the page when the button has been clicked
if(Greenfoot.mouseClicked(this))
{
Greenfoot.setWorld(new StartGame());
theme.stop();
Greenfoot.playSound("./assets/sounds/button.mp3");
}
}
}