lua - 如果对象传递 y 值则调用函数

标签 lua coronasdk

我有一个逐渐向下移动的对象,我希望每当该对象经过某个 Y 时就调用触摸函数。

所以我有一个 if 条件来检查 square.y 是否大于 150。如果该条件为真,我希望能够调用触摸函数。

我怎样才能做到这一点?

我尝试过这样做,但没有成功。

 if (square.y > 150)  then
    function square:touch (event) 
            // do something
    end
 end

最佳答案

您定义了函数 square:touch,但没有调用它。您需要使用 square:touch() 调用它:

if square.y > 150  then
    function square:touch (event) 
       print("calling touch")
    end
    square:touch()
end

如果需要,您还可以在 if 语句之外定义函数,以使其更加清晰:

function square:touch (event) 
   print("calling touch")
end

if square.y > 150  then
    square:touch()
end

关于lua - 如果对象传递 y 值则调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21948761/

相关文章:

iphone - 计算圆形 wrapper ?

android - 如何使用 gameNetwork.request( "loadScores") 获取自己的最佳分数?

lua - 电晕 SDK : Restart an app only when user press "home"

java - LuaJ 如何在Lua脚本中创建Java对象的实例?

lua - lua 中的 table.remove 行为异常

android - Corona 构建的 apk 未安装在设备中

assembly - 调试更改其他代码。科罗娜SDK

iphone - Corona LUA 和 OOP 设计

Lua reference function from inside table inside the table (Using "self"inside of table)

delphi - 如何从Delphi正确注册Lua用户数据?