【问题标题】:How can a collision event be generated after a certain amount of time?一定时间后如何产生碰撞事件?
【发布时间】:2012-08-28 03:13:23
【问题描述】:

我正在尝试学习 Corona 以制作“虚拟宠物”之类的游戏。当诸如苹果之类的物品放在地板上大约 15 秒时,我想尝试删除并重新生成该物品。

【问题讨论】:

    标签: timer coronasdk collision


    【解决方案1】:

    您不希望在某个时间后发生碰撞事件...

    您想检查一个物体在 15 秒后是否静止不动!

    只需将 enterFrame 事件添加到您的运行时。

    然后检查每个对象的位置是否发生变化并在对象上设置一个变量,例如:

    if myObject.x ~= myObject.lastX and myObject.y ~= myObject.lastY then
        myObject.timeSinceLastMovement = event.time
    end
    
    myObject.lastX = myObject.x
    myObject.lastY = myObject.y
    

    enterFrame 中的 event.time 通常以毫秒为单位跟踪应用程序启动以来的时间。

    然后您检查某个对象是否停止了 15 秒。

    if myObject.timeSinceLastMovement + 15000 < event.time then
        -- code to respawn myObject go here
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多