[英]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. 我想对交通信号灯进行仿真,如果汽车在x = 100,y = 100的位置,而灯是红色,则汽车缓慢行驶并停在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: 我不太确定您要问的是什么,但是transition.to向过渡返回了一个ID,因此您可以执行以下操作:
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! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.