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

2012/2/12

Robot Apocalypse: Collision while scrolling

N1G3L2 N1G3L2

2012/2/12

#
Hey so I need some help... In my game Robot Apocalypse, when the user presses the left or right arrow key, the world will scroll in the opposite direction. But the problem is that when the character hits an object or wall and the arrow is still being pressed, the world will continue to scroll and after a while the character can completely be outside the screen. Wow, that was confusing.. I've tried a few things but nothing seems to be working out for me. I think it's more of a matter of how a few of my classes are programmed so I won't really upload any example source since it would be pages and pages of stuff. But if anyone thinks they can help out or have time the check it out, I would be more than happy to upload the source code, so just let me know =)
Morran Morran

2012/2/12

#
N1G3L2, how does your scrolling work? Is it off of "if(Greenfoot.isKeyDown(key)) scroll()"? Maybe you want to put the call to scroll the world inside of the method to move the player. If the player can move, then the world can scroll. Make sure that the code to keep the player from running into walls is in the player's move method.
N1G3L2 N1G3L2

2012/2/12

#
Yeah that is exactly how i have it set up and I will definitely have to give this a try. thank you for the suggestion Morran =)
sp33dy sp33dy

2012/2/12

#
In my opinion, you have two options. Either: 1. keep the main character in the middle of the screen and always scrolling left or right. I.E. the character actor never moves independently. 2. Allow the character actor to move around and detect when it reaches a left/right point in which scroll will be activated. I.E. when in range of 100 pixels of left/right, allow scroll. There are likely to be other ways, but from all the games I've played since the early 80's, these are usually the two strategies employed.
You need to login to post a reply.