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

2018/6/13

Vertically Scrolling Background

ringline ringline

2018/6/13

#
Hello there, I'm just trying to get a background scroll slightly downwards - and it doesn't work. Maybe some of you can help me... I've got a background with 900x900 px. The world is set to super(900, 600, 1); The clipping I want to see in the beginning is on the bottom. So just for testing, I insert in the constructor the following line: this.getBackground().drawImage(this.getBackground(),0,-300); This works fine, now I see the bottom of the Image like I want to. But in the other direction it doesn't work, because after inserting the line: this.getBackground().drawImage(this.getBackground(),0,+1); it does not have the right effect, but it pulls the image anywhere and I only see a black screen. Shouldn't this be supposed to move the image one px down??? Thanks for all the help! ringline
Yehuda Yehuda

2018/6/13

#
I am not sure I understand what is happening but, I do know that putting a "+1" for an image's location does not move it over 1 pixel, it draws it by pixel 1.
danpost danpost

2018/6/14

#
ringline wrote...
Shouldn't this be supposed to move the image one px down???
You must understand that the background image returned by the getBackground method is always the exact same size as your world dimensions regardless of the size of the image you set the background to. Drawing on the background also has no effect on the size of the image returned. Save the full (larger than world dimensions) image in a field and draw it onto the background at different y-offsets (between -300 and 0) to scroll.
ringline ringline

2018/6/14

#
Ah, ok, thank you very much for the fast and good answer!
You need to login to post a reply.