A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Rookie Needs Help! Character won't walk on platforms...

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    4

    Rookie Needs Help! Character won't walk on platforms...

    My character keeps falling through my platforms, and I can't figure out what I'm doing wrong. Here is what I have...

    stop();

    import flash.events.KeyboardEvent;

    var KeyIsDown:uint;
    var rightKeyIsDown:Boolean = false;
    var leftKeyIsDown:Boolean = false;
    var upKeyIsDown:Boolean = false;
    var downKeyIsDown:Boolean = false;
    var canJump:Boolean = false;
    var gravity:Number = 2;
    var yVelocity:Number = 0;
    var wall_mc:Wall_mc = new Wall_mc();
    addChild(wall_mc);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
    stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);

    function PressAKey(event:KeyboardEvent):void
    {
    if (event.keyCode == Keyboard.RIGHT)
    {
    rightKeyIsDown = true;
    }
    if (event.keyCode == Keyboard.LEFT)
    {
    leftKeyIsDown = true;
    }
    if (event.keyCode == Keyboard.UP)
    {
    upKeyIsDown = true;
    }
    if (event.keyCode == Keyboard.DOWN)
    {
    downKeyIsDown = true;
    }
    }
    function ReleaseAKey(event:KeyboardEvent):void
    {
    if (event.keyCode == Keyboard.RIGHT)
    {
    rightKeyIsDown = false;
    }
    if (event.keyCode == Keyboard.LEFT)
    {
    leftKeyIsDown = false;
    }
    if (event.keyCode == Keyboard.UP)
    {
    upKeyIsDown = false;
    }
    if (event.keyCode == Keyboard.DOWN)
    {
    downKeyIsDown = false;
    }
    }

    caveman.addEventListener(Event.ENTER_FRAME,moveCav eman);

    function moveCaveman(event:Event):void
    {
    if (rightKeyIsDown)
    {
    caveman.x += 3;
    caveman.scaleX = 1;//flips caveman
    }
    if (leftKeyIsDown)
    {
    caveman.x -= 3;
    caveman.scaleX = -1;//flips caveman
    }
    if (upKeyIsDown && canJump)
    {
    yVelocity = -10;
    canJump = false;
    }
    yVelocity += gravity;

    if (! wall_mc.hitTestPoint(caveman.x,caveman.y,true))
    {
    caveman.y += yVelocity;
    }
    if (yVelocity > 15)
    {
    yVelocity = 15;
    }
    for (var i:int=0; i<10; i++)
    {
    if (wall_mc.hitTestPoint(caveman.x,caveman.y,true))
    {
    caveman.y--;
    yVelocity = 0;
    canJump = true;
    }
    }
    }

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Can you post our fla or swf file?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks for looking! Here is a swf...

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Try that again...
    Attached Files Attached Files

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    4

    Got it!

    I fixed the name and got rid of the var with the wall_mc rule, and put one instance of the block. I then double clicked it and added jpg of the object in the mc.

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