Hello I'm trying to create a game of exploration where the screen will scroll up, down, left, or right. Thanks guys!
Platform platform = new Platform(); int platformWidth = platform.getImage().getWidth(); int x = getWidth()/2; addObject(platform, x, 380); while (getUnivX((x += platformWidth)) < getScrollingWidth()) addObject(new Platform(), x, 380); x = getWidth()/2; while (getUnivX((x -= platformWidth)) > 0) addObject(new Platform(), x, 380);
public Platform(int reps)
{
GreenfootImage single = getImage();
GreenfootImage multiple = new GreenfootImage(single.getWidth()*reps, single.getHeight());
for (int i=0; i<multiple.getWidth(); i+=single.getWidth())
multiple.drawImage(single, i, 0);
setImage(multiple);
}int platformWidth = new Platform(1).getImage().getWidth(); int reps = 1+getScrollingWidth()/platformWidth; addObject(new Platform(reps), getWidth()/2, 380);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class floortiles here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Platform extends Actor
{
/**
* Act - do whatever the floortiles wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Platform()
{
GreenfootImage road = new GreenfootImage("grass.png");
GreenfootImage image = new GreenfootImage(1040, road.getHeight());
int w=road.getWidth();
for(int offset=0; offset<1040; offset+=w) image.drawImage(road, offset, 0);
setImage(image);
int platformWidth = new Platform().getImage().getWidth();
int reps = 1+getScrollingWidth()/platformWidth;
addObject(new Platform(reps), getWidth()/2, 380);
}
}