2013-02-23 59 views
0

我試圖觸發隱藏和我的表local starTable = {}觸發隱藏和顯示錶

local starTable = {} -- Set up star table 


local function showStarTable() 
-- some trigger to show the star table 
end 
timer.performWithDelay(500, showStarTable, 1) 

local function hideStarTable() 
-- some trigger to hide the star table 
end 
timer.performWithDelay(1000, hideStarTable, 1)  

一個節目是有可能實現這一

+0

starTable包含哪些元素? – atok 2013-02-24 09:12:17

回答

1

要與這裏的第一個答案走就是一個例子:

local starTable = {} 
local star1 = <display object> 


starTable:insert(star1) 

local function showStarTable() 
    starTable.alpha = 1 
end 
timer.performWithDelay(500, showStarTable, 1) 


local function hideStarTable() 
    starTable.alpha = 0 
end 
timer.performWithDelay(1000, hideStarTable, 1) 

你想堅持用實際的表或。並沒有看到什麼是真正被插入到你的啓動的,你可以嘗試:

local starTable = {} 

local star = <display object> 
starTable[1] = star 

star = <display object> 
starTable[2] = star 

star = <display object> 
starTable[3] = star 

local function showStarTable() 
    for i=1, #starTable do 
     starTable[i].star.alpha = 1 
    end 
end 
timer.performWithDelay(500, showStarTable, 1) 


local function hideStarTable() 
    for i=1, #starTable do 
     starTable[i].star.alpha = 0 
    end 
end 
timer.performWithDelay(1000, hideStarTable, 1) 

然而,第一個選項是更好的,如果它與你的程序。

+0

我剛剛注意到我的文章中有一個錯字,第一組代碼的第一行應該說「local starTable = display.newGroup()」 – ck1221 2013-02-26 21:09:44

1

你的代碼後,將執行該功能showStarTable() 1次1/2秒。然後再過半秒鐘,它會執行一次hideStarTable()。

像display.newImageRect()這樣的顯示對象是表格,所以如果這是您所指的表格,您可以通過更改對象的.alpha屬性或其可見性來顯示/隱藏它們(.isVisible = true或.isVisible = false)。然而,表本身只是信息的容器,並且通用表不可顯示。它可以包含多個顯示對象。

如果表中有可顯示的內容,在您的顯示/隱藏功能中顯示/隱藏表格內容將是您的責任。