A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Help with character movement

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

    Arrow Help with character movement

    Some of you may have seen my previous post, but basically I have an arcade machine skin that looks like a ghost is moving it as you play. One button, and one joystick.

    Here's my problem:





    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==Keyboard.LEFT) {
    joystick.gotoAndStop("left");
    _left = true;
    }
    if (joyEventGo.keyCode==Keyboard.RIGHT) {
    joystick.gotoAndStop("right");
    _right = true;
    }
    if (joyEventGo.keyCode==Keyboard.UP) {
    joystick.gotoAndStop("up");
    _up = true;
    }
    if (joyEventGo.keyCode==Keyboard.DOWN) {
    joystick.gotoAndStop("down");
    _down = true;
    }
    if (joyEventGo.keyCode==Keyboard.SPACE) {
    fire_button.gotoAndStop("down");
    _fire = true;
    }
    }

    function KeyUpList(joyEventStop:KeyboardEvent):void {
    if (joyEventStop.keyCode==Keyboard.LEFT) {
    joystick.gotoAndStop("middle");
    _left = false;
    }
    if (joyEventStop.keyCode==Keyboard.RIGHT) {
    joystick.gotoAndStop("middle");
    _right = false;
    }
    if (joyEventStop.keyCode==Keyboard.UP) {
    joystick.gotoAndStop("middle");
    _up = false;
    }
    if (joyEventStop.keyCode==Keyboard.DOWN) {
    joystick.gotoAndStop("middle");
    _down = false;
    }
    if (joyEventStop.keyCode==Keyboard.SPACE) {
    fire_button.gotoAndStop("up");
    _fire = false;
    }
    }

    function moveLeft() {
    if (_left = true) {
    spaceship.x -= shipspeed
    trace("Moving Left.");
    }
    }

    function moveRight() {
    }
    function moveUp() {
    }
    function moveDown() {
    }

    stagecontrol()




    see the part in red txt? It somehow starts as true automatically, and even when I do

    var _left:Boolean = false

    it still comes out with "Moving Left." in the output window. Event if I havent pushed left! Any help is appreciated, thank you.
    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
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    you're using the assignment ( = ) instead of the comparison ( == ) operator. Try:

    PHP Code:
    if(_left == true
    or better yet

    PHP Code:
    if(_left

  3. #3
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Hmmm. It stopped spamming the "Moving Left." thing in the output window, but now it is doing nothing.

    as you can see I didnt do an add child or anything, the ship just started on the stage. Could that cause some sort of problem?
    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
    AHA! I figured it out! It turns out that you were correct, I needed if (_left). but also, I wasn't calling the function anywhere. so there you have it. Pure stupidity.
    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

  5. #5
    Senior Member
    Join Date
    May 2009
    Posts
    138
    We're all human :P Sometimes the code you wrote in your head isn't the same as the code your fingers wrote and its hard to see your own mistakes

  6. #6
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Quote Originally Posted by redjag View Post
    We're all human :P Sometimes the code you wrote in your head isn't the same as the code your fingers wrote and its hard to see your own mistakes
    Oh, it's so true!
    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