我目前正在製作一款卡片戰鬥遊戲。在主戰場景中,我試圖展示這些牌正在互相爭鬥,他們的健康狀況正在下降,最終武器也在場邊移動。Corona在作曲家中的主動戰鬥場景
目前,當它進入戰鬥循環時,顯示屏凍結,但我一直在記錄正在發生的事情以及正在發生的戰鬥,就在現場後面。我已經把代碼頂部的戰鬥循環分成了自己的功能,並通過點擊事件來調用該功能。
我通過使用while循環中的打印語句來驗證它是否正在運行,該循環將卡的當前健康狀況和卡的名稱輸出到控制檯。目前卡片的健康狀況正在發生變化,它只是不改變場景,而是凍結舊的場景,而不會主動顯示正在發生的事情。
這裏是整個場景的代碼:
function battleScene(playerCards, enemyCards, allCards, cardHealth)
while not checkIfDead(playerCards) and not checkIfDead(enemyCards) do
for i=1, 6 do
if allCards[i]~=0 then
allCards[i]:battle()
end
print(allCards[i]:getCurHealth().." "..allCards[i]:getName())--The test to see current health of card
cardHealth[i]:setHealth(allCards[i]:getCurHealth(),allCards[i]:getHealth())
if checkIfDead(playerCards) or checkIfDead(enemyCards) then
break
end
usleep(2000)
end
end
end
---------------------------------------------------------------------------------
-- "scene:show()"
function scene:show(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Called when the scene is still off screen (but is about to come on screen).
elseif (phase == "did") then
--The current health of each card is set to max
--and then the card is rendered along with health bars
local card1=test1:render()
card1.x=display.contentCenterX-100
card1.y=display.contentCenterY-100
sceneGroup:insert(card1)
local card1Health=HealthBar:new()
card1Health.x=display.contentCenterX-100
card1Health.y=display.contentCenterY-40
card1Health:setHealth(test1:getCurHealth(), test1:getHealth())
sceneGroup:insert(card1Health)
playerCards={test4, test5, test6}
enemyCards={test1, test2, test3}
for i=1, 3 do
if playerCards[i]:getClass()=="Tank" or playerCards[i]:getClass()=="Damage" then
playerCards[i]:setBattleSet(enemyCards)
else
playerCards[i]:setBattleSet(playerCards)
end
end
for i=1, 3 do
if enemyCards[i]:getClass()=="Tank" or enemyCards[i]:getClass()=="Damage" then
enemyCards[i]:setBattleSet(playerCards)
else
enemyCards[i]:setBattleSet(enemyCards)
end
end
local allCards={test1, test2, test3, test4, test5, test6}
bubbleSort(allCards)
local cardHealth= {card1Health,card2Health,card3Health,card4Health,card5Health,card6Health}
local startBattleButton=display.newText("Start Battle", 0, 0, globals.font.regular, 18)
startBattleButton.x = display.contentCenterX
startBattleButton.y = display.contentCenterY
local function onTap(event)
startBattleButton.isVisible=false
battleScene(playerCards, enemyCards, allCards, cardHealth)
end
startBattleButton:addEventListener("tap", onTap)
sceneGroup:insert(startBattleButton)
if checkIfDead(playerCards) then
win=false
end
end
end
-1有太多的代碼,人們都忙!簡化這個例子,就像只有一張卡片一樣,你爲什麼需要6個顯示問題?此外,澄清你如何驗證它是「幕後」的工作,這是什麼意思,你怎麼知道這一點?如果您很快修復代碼,我很樂意撤銷downvote。 – Schollii
現在編輯。我仍然需要至少有其他牌在那裏顯示的戰鬥序列,雖然我刪除了顯示他們與他們的健康酒吧渲染的位。 –
好得多。當你接受時,你通常應該也會投票贊成或者評論答案爲什麼沒有upvote案件作者可以改善它。歡迎來到SO! – Schollii