PDA

View Full Version : Moving Character and Ground



seraphimglobal
May 3rd, 2007, 03:28 PM
Hello,

I have what I think is an easy question. I am making a game with a character that you move using the arrow keys. When he gets to a certain point in the window I want the ground underneath to start moving down. The code below works but the character gets stuck in ground moving only and can't move independently again. If I trace this._y I get 146 when he gets stuck. I tried a little code that would kick him back outside of that but it looked awful.




if (Key.isDown(Key.UP)) {
if (this._y>150) {
//Move the character
this._y = Math.max(this._y-distance, 0);
} else {
//Move the ground down stage
_root.ground._y += 8;
}

else if (Key.isDown(Key.DOWN)) {
if (this._y>150) {
//Move the Character
this._y = Math.max(this._y-distance, 0);
} else {
//Move the ground down up
_root.ground._y -= 8;
}
}

I appreciate any help you can provide.

pingnak
May 3rd, 2007, 09:40 PM
You might want to use two coordinate systems. Game coordinates and screen coordinates.

Then you can use a bounding box as a 'thumb' to drag the world coordinates that Flash uses to render to fit around your character.

As long as you're inside the bounding box, nothing scrolls.

If you walk past the edge, the bounding box moves just enough to put you back inside its bounds.

The nice thing about doing it this way is that it can work whichever way you move.

You could also write it so the rectangle 'chases' the character. The further past the edge, the faster the bounding box moves. The acceleration when the character moves, and deceleration when the character stops really smooths things out.