-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreditScreen.java
45 lines (40 loc) · 1.49 KB
/
CreditScreen.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
41
42
43
44
45
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class CreditScreen here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CreditScreen extends World
{
private static final String bgImageName = "CreditBackground.png";
private static final double scrollSpeed = 3;
private static final int picWidth = (new GreenfootImage(bgImageName)).getWidth();
private GreenfootImage bgImage, bgBase;
private int scrollPosition = 0;
public static GreenfootSound music = new GreenfootSound("Credits.mp3");
public CreditScreen()
{
super(800, 400, 1);
setBackground(bgImageName);
bgImage = new GreenfootImage(getBackground());
bgBase = new GreenfootImage(picWidth, getHeight());
bgBase.drawImage(bgImage, 0, 0);
addObject(new CreditSheet(), 400, 200);
addObject(new Back(), 400, 360);
music.setVolume(70);
music.play();
}
public void act(){
scrollPosition -= scrollSpeed;
while(scrollSpeed > 0 && scrollPosition < -picWidth) scrollPosition += picWidth;
while(scrollSpeed < 0 && scrollPosition > 0) scrollPosition -= picWidth;
paint(scrollPosition);
}
private void paint(int position)
{
GreenfootImage bg = getBackground();
bg.drawImage(bgBase, position, 0);
bg.drawImage(bgImage, position + picWidth, 0);
}
}