Hello, my scenario has a visible issue in which the scrolling background appears to jitter or lag every second or so. Any idea how to fix this? Thanks. (The background is made of 2 png images that scroll down below the bottom of the screen, and are then re-positioned back at the top. At this point I have tried reducing the scenario to include only the Stars actor yet the issue persists.)
import greenfoot.*;
public class Space extends World //space. the final frontier.
{
private int time;
private int score;
private int initialDelay;
Stars stars1 = new Stars();
Stars stars2 = new Stars();
public Space()
{
super(480, 600, 1, false);
GreenfootImage background = getBackground();
background.setColor(Color.BLACK);
background.fill();
setPaintOrder(ButtonMain.class, ScoreBoard.class, Hud.class, Clouds.class, SlowCloud.class,
AsteroidTwo.class, AsteroidOne.class, Explosion.class, Ship.class, StarsSmall.class, Stars.class);
score = 0;
time = 0;
initialDelay = 125;
}
public void act()
{
makeStars();
countTime();
}
private void makeStars() //this is a vertically scrolling background made of 2 images
{
addObject(stars1, 240, -300); //png image 480 X 600 (same size as game screen)
addObject(stars2, 240, 300); //png image 480 X 600 (same size as game screen)
if(stars1.getY() >= 900)
{
stars1.setLocation(240, -300); //once the image is out of site below the bottom border, move it above the top border
}
if(stars2.getY() >= 900)
{
stars2.setLocation(240, -300); //once the image is out of site below the bottom border, move it above the top border
}
}
private void countTime()
{
if (lives != 0)
{
time++;
}
}
public void storeHighScore() //Game over. Store the player score in the high score table if possible.
{
if(UserInfo.isStorageAvailable()) {
UserInfo myData = UserInfo.getMyInfo();
if (myData != null) {
if (finalScore() > myData.getScore()) {
myData.setScore (finalScore());
myData.store(); // write back to server
}
}
}
}
}
import greenfoot.*;
public class Stars extends Actor
{
private int speed;
protected void addedToWorld(World world)
{
Space space = (Space) world;
speed = 6;
}
public void act()
{
setLocation(getX(), getY()+speed);
}
}
