繁体   English   中英

如何在Corona SDK中使用过渡位置进行条件

[英]How to make condition with using transition position at Corona SDK

我想对交通信号灯进行仿真,如果汽车在x = 100,y = 100的位置,而灯是红色,则汽车缓慢行驶并停在x = 120,y = 120的位置。

我使用该脚本:

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

而且我不知道当物体移动时,如何使该物体处于颊位置。

我不太确定您要问的是什么,但是transition.to向过渡返回了一个ID,因此您可以执行以下操作:

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

因此,要检查汽车当前是否在行驶,您可以执行以下操作:

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

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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