0
所以我一直在嘗試幾天來解決這個問題。我正在與Corona進行一種簡單的塊代碼遊戲,我無法獲得播放按鈕的功能來按順序播放。我有九個不同的盒子,應該一個接一個地播放這些動作,但是相反,所有的東西都在一個功能中起作用。 它的代碼有點長,雖然它應該檢測哪些塊函數是或不在那裏。在Corona中一個接一個地執行功能?
---------------------------------------------
-----button image------
local play = display.newImage ("GoButton.png")
play.x = display.contentWidth /2 - 140
play.y = display.contentHeight /2 + 20
------later used Variables---
local b1 = 0
local b2 = 0
local b3 = 0
local b4 = 0
local b5 = 0
local b6 = 0
local b7 = 0
local b8 = 0
local b9 = 0
-----Play button code-----
function play:tap (event)
function play1()
-------------------------Box 1------------------------------------------
if b1 == 0 then
Mascot.alpha = 1
end
if b1 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b1 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b1 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b1 == 4 then
Mascot.alpha = 0.5
end
if b1 == 5 then
Mascot.xScale = -1
end
end
function play2()
-------------------------Box 2------------------------------------------
if b2 == 0 then
Mascot.alpha = 1
end
if b2 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b2 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b2 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b2 == 4 then
Mascot.alpha = 0.5
end
if b2 == 5 then
Mascot.xScale = -1
end
end
timer.performWithDelay(5000, play2)
function play3()
-------------------------Box 3------------------------------------------
if b3 == 0 then
Mascot.alpha = 1
end
if b3 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b3 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b3 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b3 == 4 then
Mascot.alpha = 0.5
end
if b3 == 5 then
Mascot.xScale = 1
end
end
timer.performWithDelay(5000, play3)
function play4()
-------------------------Box 4------------------------------------------
if b4 == 0 then
Mascot.alpha = 1
end
if b4 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b4 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b4 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b4 == 4 then
Mascot.alpha = 0.5
end
if b4 == 5 then
Mascot.xScale = -1
end
end
timer.performWithDelay(5000, play4)
function play5()
-------------------------Box 5------------------------------------------
if b5 == 0 then
Mascot.alpha = 1
end
if b5 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b5 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b5 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b5 == 4 then
Mascot.alpha = 0.5
end
if b5 == 5 then
Mascot.xScale = -1
end
end
timer.performWithDelay(5000, play5)
function play6()
-------------------------Box 6------------------------------------------
if b6 == 0 then
Mascot.alpha = 1
end
if b6 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b6 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b6 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b6 == 4 then
Mascot.alpha = 0.5
end
if b6 == 5 then
Mascot.xScale = -1
end
end
timer.performWithDelay(5000, play6)
function play7()
-------------------------Box 7------------------------------------------
if b7 == 0 then
Mascot.alpha = 1
end
if b7 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b7 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b7 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b7 == 4 then
Mascot.alpha = 0.5
end
if b7 == 5 then
Mascot.xScale = -1
end
end
timer.performWithDelay(5000, play7)
function play8()
-------------------------Box 8------------------------------------------
if b8 == 0 then
Mascot.alpha = 1
end
if b8 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b8 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b8 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b8 == 4 then
Mascot.alpha = 0.5
end
if b8 == 5 then
Mascot.xScale = -1
end
end
timer.performWithDelay(5000, play8)
function play9()
-------------------------Box 9------------------------------------------
if b9 == 0 then
Mascot.alpha = 1
end
if b9 == 1 then
Mascot:applyLinearImpulse(1, 0, Mascot.x, Mascot.y)
end
if b9 == 2 then
Mascot:applyLinearImpulse(-1, 0, Mascot.x, Mascot.y)
end
if b9 == 3 then
Mascot:applyLinearImpulse(0, -1, Mascot.x, Mascot.y)
end
if b9 == 4 then
Mascot.alpha = 0.5
end
if b9 == 5 then
Mascot.xScale = -1
end
b1 = 0
b2 = 0
b3 = 0
b4 = 0
b5 = 0
b6 = 0
b7 = 0
b8 = 0
b9 = 0
if walk == 1 then
walkSpawn:removeSelf()
walk = 0
end
if attack == 1 then
attackSpawn:removeSelf()
attack = 0
end
if jump == 1 then
jumpSpawn:removeSelf()
jump = 0
end
if flip == 1 then
flipSpawn:removeSelf()
flip = 0
end
if face == 1 then
faceSpawn:removeSelf()
face = 0
end
end
timer.performWithDelay(5000, play9)
print ("derp")
Runtime:addEventListener("enterFrame", play1)
Runtime:addEventListener("enterFrame", play2)
Runtime:addEventListener("enterFrame", play3)
Runtime:addEventListener("enterFrame", play4)
Runtime:addEventListener("enterFrame", play5)
Runtime:addEventListener("enterFrame", play6)
Runtime:addEventListener("enterFrame", play7)
Runtime:addEventListener("enterFrame", play8)
Runtime:addEventListener("enterFrame", play9)
end
play:addEventListener("tap", play)
---------------------------------------
如果任何人都可以幫助這將是一個巨大的忙,謝謝。
感謝您的相應。 當我刪除EventListeners時,該函數根本沒有響應。 我正在嘗試創建一種像劃痕編碼這樣的編碼模擬遊戲,並且我已經得到了可以拖入框中的「代碼」塊。根據用戶具有塊的順序,我希望機器人在按下「播放」按鈕時採取適當的操作。只有九個可能的位置拖動塊和五個不同的功能,因爲我想保持它相當簡單。 – Rootface