1. Check out our companion app, Forums for Android! Download from Google Play

if(Key.isDown) to be used in a button

Discussion in 'Application Development' started by juliuz0001, Jan 9, 2013.

  1. juliuz0001

    juliuz0001 Member
    Thread Starter
    15

    May 20, 2012
    10
    0
    15
    Hi guys! Please help me T_T

    I am making a android game that has a left and right movement.. I made two buttons for the left and right movements.
    What i want is to make my character move when I press the left/right button, i don't need to use keyboard movements..
    So how can i make my character move using the left/right button.

    These are my codes actionscript 3.0:



    import flash.events.Event;


    hero.gotoAndStop('still');


    stage.addEventListener(Event.ENTER_FRAME,onenter)


    function onenter(e:Event):void{

    if(Key.isDown(Key.RIGHT)){
    hero.x+=5;
    hero.scaleX=-1;
    hero.gotoAndStop('walking');
    }

    else if(Key.isDown(Key.LEFT)){
    hero.x-=5;
    hero.scaleX=1;
    hero.gotoAndStop('walking');
    }
    else hero.gotoAndStop('still');
    }
     

    Advertisement

Share This Page

Loading...