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

Report as inappropriate.

MatheMagician
MatheMagician presents ...

2012/5/25

Scrolling Man

I got the idea from Celestics free scrolling world. I am posting it just as a starting point for beginners so that they get the idea of how to make their own scrolling games. If you just want to use this code for your games, here are some directions on how to use it.

Place your main actor that the rest of the world will be scrolling around in the man class and everything that will move when he scrolls in the other class. You can leave stuff like health bars or counters somewhere else and they will not be affected.

In order to limit the range that your actor can travel through (i.e. so that he will not go off of the image) call the can(direction) method. The numbers that represent which directions are defined in the Man class. Currently the range is set to -400 to 0 and from -600 to 0. To modify them go to the can class in the Man's code and modify the greater than brackets. Remember that everything in this world is flipped from usual java.

In order to set the starting position of the character, change the x, y variables in the scroller class to negatives of the position you want him to start in.

In order to set the image you want to use as your background, change the scroller's testScroll variable, and set the scroller's image to that.

There is a tutorial on this under Scrolling Man\doc\Tutorial.rtf in the download. The result is uploaded here http://www.greenfoot.org/scenarios/5704.

5502 views / 12 in the last 7 days

4 votes | 0 in the last 7 days

Tags: game demo with-source

This scenario is a member of: Greenfoot courses, Scrolling games


open in greenfoot
Your browser does not support the canvas tag.
MoritzMoritz

2012/7/15

ok thank you very much ..but where and when will you post this tutorials? by the way; are you german? because I think Mathe ... it is german, isnĀ“t it? =))
MatheMagicianMatheMagician

2012/7/15

I'll probably create a word document or something and put it in the project files of my game in the next update. That way, it will be right there for anybody who downloads the code. Also, I am not German, however, my favorite book is the Phantom Tollbooth, and one of my favorite characters is the MatheMagician who has a pencil for a staff.
SPowerSPower

2012/7/15

@MatheMagician when your tutorial is done, would you please add it to this collection?: http://www.greenfoot.org/collections/321
A new version of this scenario was uploaded on Tue Jul 17 16:37:18 UTC 2012 Added the tutorial and a hitEdge() method.
MoritzMoritz

2012/7/17

thank you soo much =))
MatheMagicianMatheMagician

2012/7/17

You are welcome.
SPowerSPower

2012/8/4

I couldn't find the course, since the doc folder is re-created when you look at documentation. What you need to do, is create a new folder (in the same folder as images and sounds), and put the course in there.
A new version of this scenario was uploaded on Sat Aug 04 12:43:41 UTC 2012 Fixed some documentation problems.
groengeelgroengeel

2012/9/12

Thank you! I was looking very hard for this.. ;-)
MatheMagicianMatheMagician

2012/9/12

I am happy it was helpful to you. Um, could you please press the like button, though?

See all comments

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

Who likes this?

Entity1037 vonmeth Moritz jerty