Stop a controlling object to move in Corona sdk -
i have 2 controls in space shooter-like game, left , right. ship move left , right , when ship moves left of x=40 (far left), revert x=40 , disable "move left" function temporarily, problem whenever move far left or far right of screen, middle of screen, ship moves further x=40(about x=35) moves , continues until let go of button. how can make when move ship far left, stops , lets me move right?
here code:
function left:touch() if(car01.x>40 , car01.x<280) motionx=-speed; return false end end left:addeventlistener("touch",left) function left:touch2() motionx=0; end local function movecar(event) if(car01.x>40 , car01.x<280) car01.x=car01.x+motionx return false elseif(car01.x==40) car01.angularvelocity=0 left:addeventlistener("touch2",left) car01.x=car01.x+motionx elseif(car01.x<40) car01.x=40 end end runtime:addeventlistener("enterframe",movecar) local function stop(event) if (event.phase=="ended") motionx=0; return true end end runtime:addeventlistener("touch",stop)
is is looking for..?
create background(bg), left , right controls(left , right resp.). then:
local function moveleft() if(car01.x>40)then car01.x = car01.x - 40 end end left:addeventlistener("tap",moveleft) local function moveright() if(car01.x<280)then car01.x = car01.x + 40 end end right:addeventlistener("tap",moveright) keeo coding....... :)
Comments
Post a Comment