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

Report as inappropriate.

SPower
SPower presents ...

2012/8/14

Scrolling world

An implementation of a way to scroll through a world too big to fit on screen.

The important classes are ScrollWorld and ScrollActor, so you would do well to read the documentation of those two classes. If you've got further questions, you may leave a comment here (though please, don't post full code here: do that in a discussion).

As a demo, I made a bug that walks around in the world. It is controlled with your mouse and the up/down keys. Feel free to use the demo code in the Bug class, as all of the movement code is in there.

You're free to use this in your own games, but if you do so, I would appreciate giving credit as to where you got the scrolling code from.

26605 views / 50 in the last 7 days

17 votes | 0 in the last 7 days

Tags: mouse demo with-source scrolling

This scenario is a member of: Reusable actors & support classes, Scrolling games


open in greenfoot

There is no HTML 5 translation of this scenario available.
View legacy version (requires Java plugin)

This scenarios uses Java features that are not available for use after conversion to HTML 5. Please try the legacy version, which requires the Java plugin to be installed.

A new version of this scenario was uploaded on Thu Oct 31 20:11:27 UTC 2013 Bug fixes in the ScrollActor class
A new version of this scenario was uploaded on Thu Oct 31 20:15:25 UTC 2013 Fixed another bug in ScrollActor
A new version of this scenario was uploaded on Fri Nov 01 16:26:32 UTC 2013 Fixed a bug where removing a ScrollActor would case an exception
TaviTavi

2013/11/1

Thanks again :) .
oscarreksoscarreks

2015/10/1

I used this in a small class assignment. ScrollWorld and ScrollActor simplified a lot of stuff. Many thanks! You can find it here: http://www.greenfoot.org/scenarios/15036
max_thuremax_thure

2017/2/2

I am using your Scenario in one of my School Projects and it is helping me a lot. However, I got an issue, where I add an Object to the World and for some reason the globalX and globalY variables become 0 instead of giving the real values. This only happens when the CameraFollower is not moving. Any Suggestions?
danpostdanpost

2017/2/4

@max_thure, please start a discussion thread on this. Include what code you have for your world and point out which part refers to the object you are adding and having the problem with. The moving or not moving of the 'mainActor' should not have any bearing on how other objects are added into the world.
max_thuremax_thure

2017/2/8

Just did so. Still needs to get approved. For anyone that may have an idea: I gave it the topic "Problems with the Scrolling World"
EmelgaEmelga

2017/11/23

Been trying to use this concept of a scrolling screen in a little project of mine, however I am having trouble getting started, I want the camera to move exactly as the main character does but I'm finding it difficult to get my head around the "addCameraFollower" operation as I would assume this would be the operation to make it follow the main character. Any help on how to structure the operation would be greatly appreciated, as I have a main character as "Wombat" as a sub class of ScrollActor but have no idea what to put in the place of "ScrollActor" or "cameraFollower" in this operation (For reference here is the documentation of the operation itself - addCameraFollower(ScrollActor cameraFollower, int x, int y))
Super_HippoSuper_Hippo

2017/11/23

Isn't your wombat exactly what the ladybug is in this project? The 'addCameraFollower' method is not the method which "moves the screen", it adds the actor which will be followed. Open the 'DemoWorld' and check how it was done.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

priscan791 Oldmoe kidi99 askgriff CarlosOlea amin miles7191 Blkhwk93 Jrm1715 -nic- Game/maniac groengeel Cocky USBest CrazyGamer1122 Chantal davemib123