Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var vx:int = 0;
- var rightInnerBoundary:uint;
- var leftInnerBoundary:uint;
- {
- function BetterScrolling() {
- if(!stage){
- this.addEventListener(Event.ADDED_TO_STAGE, stageReady);
- }else{
- stageReady();
- }
- }
- function stageReady(e:Event = null):void {
- stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
- stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
- stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
- rightInnerBoundary
- = (stage.stageWidth /2) + (stage.stageWidth /4);
- leftInnerBoundary
- = (stage.stageWidth /2) - (stage.stageWidth /4);
- }
- function keyDownHandler(event: KeyboardEvent): void
- {
- if (event.keyCode == Keyboard.LEFT)
- {
- vx = -5;
- character.gotoAndPlay("WALKL");
- } else if (event.keyCode == Keyboard.RIGHT)
- {
- vx = 5;
- character.gotoAndPlay("WALKR");
- }
- }
- function keyUpHandler(event: KeyboardEvent): void
- {
- if (event.keyCode == Keyboard.LEFT)
- {
- vx = 0;
- character.gotoAndPlay("ILDEL");
- } if (event.keyCode == Keyboard.RIGHT)
- {
- vx = 0;
- character.gotoAndPlay("ILDER");
- }
- }
- function enterFrameHandler(event: Event): void {
- {
- character.x += vx
- if (character.x < leftInnerBoundary)
- {
- character.x = leftInnerBoundary;
- rightInnerBoundary = (stage.stageWidth /2) + (stage.stageWidth /4)
- background.x -= vx /2;
- foreground.x -= vx;
- } if (character.x + character.width > rightInnerBoundary)
- {
- character.x = rightInnerBoundary - character.width
- leftInnerBoundary = (stage.stageWidth /2) + (stage.stageWidth /4)
- background.x -= vx /2;
- foreground.x -= vx;
- if (foreground.x > 0)
- {
- foreground.x = 0;
- background.x
- = -(background.width - stage.stageWidth) /4;
- leftInnerBoundary = 0;
- }
- if (foreground.x < stage.stageWidth - foreground.width)
- {
- foreground.x = stage.stageWidth - foreground.width;
- background.x
- = ((background.width - stage.stageWidth) /4) * -3;
- rightInnerBoundary = stage.stageWidth;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment