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

2012/1/17

Sidescrolling with an end

Blight Blight

2012/1/17

#
Hi, I'm currently using this sidescrolling code: http://www.greenfoot.org/scenarios/3767 But there is no "end" in this code, if you know what I mean. You can just continue walking without ever facing a wall. I want the sidescrolling to stop as soon as my background image doesn't go any further. Like hitting the world edge when the image ends. Anyone know how to do this? Thanks in advance.
davmac davmac

2012/1/17

#
Think about the condition(s) that would be true at the end of the world. How could you express this in code? When you move right (for example) it probably says something like : if (Greenfoot.isKeyDown("right") { // movement code here } So, you'd need to change that to only allow movement when the edge condition isn't true. if (Greenfoot.isKeyDown("right") && ! edge_condition) { // movement code here } Replace 'edge_condition' with a suitable condition. Probably this condition is a function of the current position and the width of the world.
Blight Blight

2012/1/17

#
Thanks for your reply. I understand what you mean, but how do I make a condition like this if the background is a long image? Thanks in advance.
davmac davmac

2012/1/17

#
Well, how does the code keep track of the position within the world (i.e. the amount the background has scrolled)? I'm not looking at the code right now, but I assume there is some variable somewhere which tracks this?
You need to login to post a reply.