减少速度数值的 LUA。

如何通过每10秒减少 star1.movementSpeed = 10000; 来增加 movementSpeed

我尝试了这个,但无法确定我做错了什么。

function initStar()
local star1 = {}
star1.imgpath = "Star1.png"; --设置星星的图像路径
star1.movementSpeed = 10000; --确定星星的移动速度
table.insert(starTable, star1); --将星星插入到 starTable 中
end

 local function star1incr() -- 每次调用时增加速度值
 movementSpeed = movementSpeed - 1
 star1.movementSpeed = "movementSpeed: " .. movementSpeed
 end

 timer.performWithDelay(10000, star1incr, 0)
点赞
用户1442917
用户1442917

你需要在 initStar()star1incr() 之间共享一个变量(顺便说一句,“通过减少...movementSpeed来增加movementSpeed”听起来不太对);可以采用以下类似的方法:

local star1 = {}

function initStar()
  star1.imgpath = "Star1.png" --为星星设置图片路径
  star1.movementSpeed = 10000 --确定星星的移动速度
end --结束initStar()

local function star1incr()
  star1.movementSpeed = star1.movementSpeed - 1
end

timer.performWithDelay(10000, star1incr, 0)

star1 变量将在 initStarstar1incr 函数之间共享(在 Lua 术语中被称为 upvalue)。

2013-02-21 05:15:08
用户1993254
用户1993254

通过以下方式进行修正:

   local function star1incr()
        starTable[1].movementSpeed = starTable[1].movementSpeed - 1
        print( "- 1" )
    end
2013-02-21 13:54:09