简体   繁体   中英

How to make condition with using transition position at Corona SDK

I want to make the simulation of traffic light, if the car position at x=100, y=100 and the light is red, the car moving slowly and stop at position x=120, y=120.

I use that script :

local function loopcar()
  car.x =430
   car.y=300
    transition.to(car, { x=0,y=50,time=3000,tag="mycar", onComplete=function()

      car.x =430
      car.y=300
      transition.to(car, { x=0,y=50,time=3000,tag="mycar", onComplete=loopcar } )
    end } )
end -- for looping the car

and I don't know how ta make condition that chek position when that object moving.

I'm not quite sure what you're trying to ask, but transition.to returns a id to the transition so you could do:

car.animation = transition.to(car, { x=0,y=50,time=3000,tag="mycar", onComplete=function()
    car.animation = nil
end})

So to check if the car is currently moving you would do:

if (car.animation ~= nil)
    print("Car is moving")
else
    print("Car is NOT moving")
end

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM