This site requires JavaScript, please enable it in your browser!
Greenfoot back
carterfootball
carterfootball wrote ...

2011/11/30

In need of code to make the screen scroll.

carterfootball carterfootball

2011/11/30

#
Is there any code to make the world scroll contantly in the downward direction? we are in need of this to make a Fall Down game.
carterfootball carterfootball

2011/11/30

#
*world scroll constantly* that is
darkmist255 darkmist255

2011/11/30

#
You could make a long series of images that are scrolling, but I REALLY don't think you want to do that. I'll be eager to hear if someone has an answer.
AwesomeNameGuy AwesomeNameGuy

2011/12/1

#
What I would try is to have a greenfoot image in the background, and have it take up the whole background screen. Then I would draw other images on that image, and so if you want to make it look like it's scrolling down, just draw the other images on it a little higher each frame. You can do this repeatedly with images over and over again to make it look like it's scrolling down.
mal mal

2011/12/1

#
We used this method in a project we're working on now: ---------------------------------------------------------------
private GreenfootImage backgroundWorld = new GreenfootImage("backgroundTest1.jpg");
private GreenfootImage currentBackground = new GreenfootImage(1000,600);
-------------------------------------------------------
super(1100, 600, 1, false);  
        currentBackground.drawImage(backgroundWorld, 0, 0);
        setBackground(currentBackground); 
---------------------------------------------------------------------------------------- then in another method called scrollTerrain() we do this:
xPosition -= 1;
        currentBackground.drawImage(backgroundWorld, xPosition, 0);
        setBackground(currentBackground);
As I'm sure you can tell this scrolls from left to right, but I'm sure you can modify it to your needs. Our backgroundTest1.jpg is 10,000 px by 600px, when we get to the end we reset and start again. hope that helps.
mal mal

2011/12/1

#
It's worth noting that on this line:
super(1100, 600, 1, false);  
The word "false" allows actors to move off screen.
mal mal

2011/12/1

#
We have since looked at having a sequence of images that are added just before they are due to appear on screen and then removed once they pass off the other side of the screen. You can cycle through an array of smaller images continuously that way.
You need to login to post a reply.