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

Report as inappropriate.

KalleLarsson
KalleLarsson presents ...

2014/8/14

Smooth Scrolling classes

arrows to move, spacebar to stop.

*** SCROLL DOWN TO PLAY, READ IF YOU WANT TO KNOW MORE****
This are some abstract superclasses that makes super-smooth un-bounded scrolling in both directions possible for you to use in your games.
There are some example Actors made just to show the scrolling. You can remove all of them, except the player, since he controls the camera. (or see how it's done and then remove him, but you can just add your functionality in this player instead)

****info****
The scrolling is made by implementing a fictional cam that can be moved. As it is now it follows the player, but you can move it however you want, which could be cool if you want to make a quick sweep over your level or something to show a scary boss at the end ;)

Otherwise, do as you normally do, but build BIG levels to scroll around in :)

Anyways, since we have a cam, Everything that should scroll, must be drawn as a function of where the camera is. Thus all objects that should scroll with the cam must call a function called drawMe() in their act method (or at least when you want them to scroll correctly, if you have thouands of objects it might be smart to implement something that just moves the ones the camera sees, but this I leave up to you... ;) )

**more detailed info**

Scrolling actors do not work in the "standard" coordninate system, (the one that describes the screen we see at the moment, Or as we see it in this, the current camera view). instead thier coordnates are the xCoord, and yCoord, which refer to the total World, not just the part that the camera looks at. So if you use getX() etc, you will get the x-coordinate in the current window (camera view), but if you want to use the position of objects in the real woorld, you should refer to the xCoord and yCoord.
Example:
you have a really long level (Think super mario bros level where you star far to the left, xCoord=0), and then scroll your way faaaar to the right
where the goal is, (xCoord=100000000) If you want to make the game change level when the player passes the goal you have to check for
xCoord > 100000000. Using getX() will only return the x coordinate of the player in the screen (standard greenfoot between 0 and 600)..


In this example, the camera is not allowed to scroll that much to the left, or that much up, but these limits are just put there by me (the camera also stops following you if you go far to the right or far down, xCoord=3200, yCoord=1200). These limits should be where your level has its limits, because it doesn't look good if the camera pans outside the level..

If you want to se this scrolling functionality in a game example, see scenario 12048

3728 views / 903 in the last 7 days

Tags: demo scrolling scroll sidescroller support classes multidirectional shell

open in greenfoot
Your browser is ignoring the <APPLET> tag.

No Comments

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

Who likes this?

No votes yet.