A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [CS4] Movement Lag Problem

  1. #1
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196

    [CS4] Movement Lag Problem

    Hello everyone!

    I am messing around with a flash game, and I have a border that looks like an arcade button and joystick. There is a simple space loop, to make it look like flying.

    My problem is that the ship lags when you hit an arrow key. Many video gamers know how annoying it is to not move easily. Thus, this is a big problem.

    Please help out, all Ideas are appreciated.


    ___---^^^---___
    RESOURCES

    Flash: http://xenelement.blogspot.com/2009/...ce-arcade.html


    Code:
    var _left:Boolean;
    var _right:Boolean;
    var _up:Boolean;
    var _down:Boolean;
    var _fire:Boolean;
    var shipspeed:Number=5;
    
    function stagecontrol() {
    
    	stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDownList);
    	stage.addEventListener(KeyboardEvent.KEY_UP, KeyUpList);
    
    }
    
    function KeyDownList(joyEventGo:KeyboardEvent):void {
    	if (joyEventGo.keyCode==37) {
    		_left=true;
    		moveLeft();
    	}
    	if (joyEventGo.keyCode==39) {
    		_right=true;
    		moveRight();
    	}
    	if (joyEventGo.keyCode==38) {
    		_up=true;
    		moveUp();
    	}
    	if (joyEventGo.keyCode==40) {
    		_down=true;
    		moveDown();
    	}
    	if (joyEventGo.keyCode==Keyboard.SPACE) {
    		_fire=true;
    		fireGun();
    	}
    }
    
    function KeyUpList(joyEventStop:KeyboardEvent):void {
    	if (joyEventStop.keyCode==Keyboard.LEFT) {
    		_left=false;
    		joystickReset();
    	}
    	if (joyEventStop.keyCode==Keyboard.RIGHT) {
    		_right=false;
    		joystickReset();
    	}
    	if (joyEventStop.keyCode==Keyboard.UP) {
    		_up=false;
    		joystickReset();
    	}
    	if (joyEventStop.keyCode==Keyboard.DOWN) {
    		_down=false;
    		joystickReset();
    	}
    	if (joyEventStop.keyCode==Keyboard.SPACE) {
    		fire_button.gotoAndStop("up");
    		_fire=false;
    	}
    }
    
    function moveLeft() {
    	if (_left) {
    		joystick.gotoAndStop("left");
    		spaceship.x-=shipspeed;
    	}
    }
    
    function moveRight() {
    	if (_right) {
    		spaceship.x+=shipspeed;
    		joystick.gotoAndStop("right");
    	}
    }
    
    function moveUp() {
    	if (_up) {
    		spaceship.y-=shipspeed;
    		joystick.gotoAndStop("up");
    	}
    }
    
    function moveDown() {
    	if (_down) {
    		spaceship.y+=shipspeed;
    		joystick.gotoAndStop("down");
    	}
    }
    
    function fireGun() {
    	if (_fire) {
    		fire_button.gotoAndStop("down");
    	}
    }
    function joystickReset() {
    	if (! _left&&! _right&&! _up&&! _down) {
    		joystick.gotoAndStop("middle");
    	}
    }
    stagecontrol();
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  2. #2

    Key.isDown in AS3

    This was a problem that I've face when I first started to use AS3 ,but there is a work around to this problem. The Key.isDown() function was removed for some security reasons but the keyobject.as will help you get past the problem and give back the functionality of Key class of AS1 and AS2. Get the keyObject file from here. There is a video tutorial on character animation and movement that shows you how to use the class here

  3. #3
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Thanks! I'll try it out!
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  4. #4
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    This was perfect! Thanks VERY much! There is absolutely no lag at all! I'm surprised adobe hasn't bothered to offer a patch for this though, it's very annoying.

    Your advice was right on the dot, thank you very much! That tutorial also helped my many other questions!

    Onenterflash, awesome job!
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center