0

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

我已经尝试过了,但无法弄清楚我做错了什么

function initStar()
local star1 = {}
star1.imgpath = "Star1.png"; --Set Image Path for Star
star1.movementSpeed = 10000; --Determines the movement speed of star
table.insert(starTable, star1); --Insert Star into starTable
end --END initStar()    


 local function star1incr() -- increments Speed value every time it is called
 movementSpeed = movementSpeed - 1
 star1.movementSpeed = "movementSpeed: " .. movementSpeed 
 end

 timer.performWithDelay(10000, star1incr, 0)
4

2 回答 2

2

通过使用修复

   local function star1incr()
        starTable[1].movementSpeed = starTable[1].movementSpeed - 1
        print( "- 1" )
    end
于 2013-02-21T13:54:09.860 回答
1

您需要有一个可以在initStar()和之间共享的变量star1incr()(顺便说一句,“movementSpeed通过减少增加...movementSpeed听起来不正确);这样的事情可能会起作用:

local star1 = {}

function initStar()
  star1.imgpath = "Star1.png" --Set Image Path for Star
  star1.movementSpeed = 10000 --Determines the movement speed of star
end --END initStar()    


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

timer.performWithDelay(10000, star1incr, 0)

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

于 2013-02-21T05:15:08.323 回答