我想根據變量在特定區域顯示圖像。例如,當用戶點擊一個化身時,它會顯示一個特定的圖像。一旦他點擊其他頭像,其他圖像將被顯示。根據變量顯示圖像並隱藏它
我試圖刪除以前的圖像,並顯示新的,但它說「試圖調用removeself()與零值」。
定義在開始表:
local item_bigsize = {}
所以我想這:
item[i] = display.newImageRect("items/"..items['pos'..i..'_name']..".png", 80 , 80)
item[i].x = holder_2[i].x+10
item[i].anchorX=0
item[i].y=holder_2[i].y
itemGroup:insert (item[i])
item[i].destination=i
item[i]:addEventListener("touch", onSwitchPress)
和功能onSwitchPress()的工作原理是這樣的:
function onSwitchPress(event)
i=event.target.destination
if (event.phase=="began") then
title_item.text=""
desc_item.text=""
for n=1,3 do
if n~=i then
item_bigsize[n]:removeSelf()
end
n=n+1
end
elseif (event.phase == "ended") then
item_bigsize[i] = display.newImageRect("items/"..items['pos'..i..'_name']..".png", 240 , 240)
item_bigsize[i].x = 950
item_bigsize[i].anchorX=0
item_bigsize[i].y=display.contentCenterY-130
group:insert (item_bigsize[i])
title_item.text=items['pos'..i..'_title']
desc_item.text=items['pos'..i..'_details']
end
end
你在哪裏定義「item_bigsize []」表? (此外,您忘記了該表格中的索引n) – rsc 2014-10-17 17:00:11
在「必需文件」後面的起始文件LUA中 – 2014-10-17 17:12:00
您可以使用item [i] .isVisible = true'來顯示圖像,並使用'false'來隱藏他們。 – Albert 2014-10-20 05:34:19