The Second Step in Your 2D game
Ok last time we made our character move around the screen both allowing for diagnoal movement and stop the diagonal movement. Now we will make our character able to move around a bigger map, bigger than the stage is!
|
OK first you need to add some more code to move the stage so we can move around the map.
So open the actions menu for our character and edit the enterFrame code to match the following: onClipEvent(enterFrame){ if(Key.isDown(Key.LEFT)){ this._x -= leftspeed; _root._x +=leftspeed; } if(Key.isDown(Key.RIGHT)){ this._x += rightspeed; _root._x -=rightspeed; } if(Key.isDown(Key.UP)){ this._y -= upspeed; _root._y +=upspeed; } if(Key.isDown(Key.DOWN)){ this._y += downspeed; _root._y -=downspeed; } } First 'problem' you will see if you play this: IT DOESN'T MOVE!! You are actually wrong there because you are moving the stage in the same direction to what you are moving so it looks like nothing is happening. Try this draw a few lines randomly around the place, even off stage and now try it, your moving aren't you! You might also be thinking "why are the signs different for the _root code?" well that's simple. With the code we put on the character it was moving how we want (e.g. push up move up). But say we leave the signs the same then what happens is the stage moves up when you push up which looks like everything is moving down. Onto Part 3. |