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

2015/4/29

how to scroll

wheman1 wheman1

2015/4/29

#
hey i made a game in greenfoot but i dont know how to make the screen scroll when i move my player. i want him to stay in the middle of the screen but the background to move. please help!
danpost danpost

2015/4/29

#
My Bee Quick (ImgScroll Demo) scenario has an ImgScroll class that is used to keep the boy in the middle of the screen while allowing scrolling to the limits of the background image. You can add the class (un-modified) into your project and easily use it. If you look at the Welt class, you will see 5 lines of interest. Lines 18 and 19 declare fields that hold the scrolling engine (scroller) and the main character (boy). Line 32 creates the ImgScroll object and line 38 creates the Boy object and adds it into the world. Both are assigned to their appropriate previously declared fields. Finally, line 68 is used to perform the actual scrolling keeping the boy in the center of the world, if possible without scrolling beyond the limits of the scrolling background image. That is it as far as scrolling. As a sidenote, there is also an example of making use of scrolling information in the Web class, which was needed to determine where it was with respect to the scrolling area instead of just the world window (used to draw the mini-map properly).
You need to login to post a reply.