2012-08-08 29 views
0

我正在創建一款遊戲,並且玩家必須收集硬幣才能獲得更大的分數。有3個硬幣,當你收集一個硬幣時,它會顯示在用戶界面的「硬幣欄」上。硬幣有3個空洞(如Cut the Rope和其他遊戲)。目前,當玩家收集第二個硬幣時,酒吧中的第二個洞被填滿。我希望這些洞依次被填滿,以便收集沒有收集第一個硬幣的第二個硬幣將填滿第一個洞。按照遊戲順序收集物品(Corona SDK)

下面是代碼:

------投幣酒吧

local coin_bar = {} 
    for i=1,3 do 
     coin_bar[i] = display.newImage ("coin_bar.png", 57, 57) 
    end 

    coin_bar[1].x = 325 
    coin_bar[1].y = 37 
    coin_bar[2].x = 385 
    coin_bar[2].y = 37 
    coin_bar[3].x = 445 
    coin_bar[3].y = 37 

--add硬幣和處理

local coinSprites=grabber.grabSheet("starAnim") 
    local coinGroup = display.newGroup() 
    local coins = {} 
    isLiving = {} 
    for i=1,3 do 
     isLiving[i] = 1 
     coins[i] = coinSprites:grabSprite("",true,{ starAnim={1,6,200,0}}) 
     coins[i]:playClip("starAnim") 
     coinGroup:insert(coins[i]) 
    end 

    local function coinCollect(event) 
     for i=1, 3 do -- Nr of Coins 
      coin_clear = false 
      if isLiving[i] == 1 then 
       if ball.x > coins[i].x -40 and ball.x < coins[i].x +40 
       and ball.y > coins[i].y -40 and ball.y < coins[i].y +40 then 
       coins[i]:removeSelf() 
       coins[i] = nil 
       coins[i] = display.newImage ("coin_bar_collected.png", 57, 57) 
       coins[i].x = coin_bar[i].x 
       coins[i].y = coin_bar[i].y 
       isLiving[i] = 0 
       end 
      end 
     end 
    end 

    Runtime:addEventListener("enterFrame", coinCollect) 

回答

0

嘗試更換所有的東西在這個硬幣吧:

------Coin Bar 

local coin_bar = {} 
for i=1,3 do 
    coin_bar[i] = display.newImage ("coin_bar.png", 325+(i*60), 37) 
end 

看看是否可以解決您的問題。

0

爲什麼不加一個屬性收集硬幣吧跟蹤上次使用的位置和使用?即:

local coin_bar = {collected = 0} 

... 

local function coinCollect(event) 
    for i=1, 3 do -- Nr of Coins 
     coin_clear = false 
     if isLiving[i] == 1 then 
      if ball.x > coins[i].x -40 and ball.x < coins[i].x +40 
      and ball.y > coins[i].y -40 and ball.y < coins[i].y +40 then 
      coins[i]:removeSelf() 
      coins[i] = nil 
      coins[i] = display.newImage ("coin_bar_collected.png", 57, 57) 
      local bar_index = coin_bar.collected + 1 
      coins[i].x = coin_bar[bar_index].x 
      coins[i].y = coin_bar[bar_index].y 
      coin_bar.collected = bar_index 
      isLiving[i] = 0 
      end 
     end 
    end 
end 
+0

謝謝你的人!硬幣現在正確收集! – barmyman 2012-08-09 22:31:43

+0

你不介意幫助我這個小東西嗎? http://stackoverflow.com/questions/10283740/collision-of-a-drawed-line-and-objectscorona-sdk在此先感謝! – barmyman 2012-08-09 22:33:31