2012-06-06 78 views
0

在這個應用程序中,我使用Corona SDK創建,當你贏得文本「你贏」可能會出現,但沒有。我可以張貼的所有代碼,但我不認爲其餘的將是hepful,所以這裏只是呈香:Lua - 在Corona SDK中不顯示文字

_H = display.contentHeight; 
_W = display.contentWidth; 
mRand = math.random; 
o = 0; 
time_remain = 20; 
time_up = false; 
total_orbs = 45; 
total_secs = 20; 
ready = false; 

local backGround = display.newImage("media/bg.png"); 

backGround.xScale = 2; 
backGround.yScale = 2; 

loseMSG = display.newText("You Lose!", _W/2, _H/2, nil, 50) 
loseMSG.isVisible = false 

winMSG = display.newText("You Win!", _W/2, _H/2, nil, 50) 
winMSG.isVisible = false 

local countdowntxt = display.newText(time_remain, 0, 0, native.systemFont, 60); 
countdowntxt.xScale = .5; countdowntxt.yScale = .5; 
countdowntxt:setReferencePoint(display.BottomRightReferencePoint); 
countdowntxt.x = _W-20; display.y = _H-20; 
countdowntxt:setTextColor(0, 0, 0) 


function winLose(condition) 
if (condition == "Win") then 
    bgAlpha = display.newImage("media/bgAlpha.png"); 
    bgAlpha.xScale = 2; 
    bgAlpha.yScale = 2; 
    winMSG.isVisible = true -- Here the win text should become visible, but doesn't 
elseif (condition == "Fail") then 
    bgAlpha = display.newImage("media/bgAlpha.png"); 
    bgAlpha.xScale = 2; 
    bgAlpha.yScale = 2; 
    loseMSG.isVisible = true   
end 

任何想法,爲什麼?

+1

Lua不是首字母縮寫,它是一個名字。所以它是Lua,不是LUA,除非你在喊。 – BMitch

+0

對不起,這個錯誤,拖動大寫鎖定;) – Zoske

回答

0

爲什麼你給字體值爲零? ATLEAST通過默認的系統字體

loseMSG = display.newText("You Lose!", _W/2, _H/2, native.systemFont, 50) 
winMSG = display.newText("You Win!", _W/2, _H/2, native.systemFont, 50) 
+0

我也嘗試使用native.systemFont,但結果是一樣的,所以我決定使用一個圖像。也許有點重,但更容易放置:)謝謝你的幫助 – Zoske

1

你需要採取分而治之的辦法。

這是行不通的?

winMSG = display.newText("You Win!", _W/2, _H/2, nil, 50) 
winMSG.isVisible = true <-- note this is set to true 

它呢?

是否winLose每一個被調用?在其中放置一個打印語句或一個斷點或您在平臺上用於調試的任何內容。

它呢?

變量condition包含什麼?檢查/打印出來,並確認它確實是「贏」,相同的情況下,沒有空格等,或者你可以把打印語句放在該功能的適當分支,以確保它被擊中。

這樣好嗎?

如果您刪除bgAlpha代碼,它會顯示嗎?

等等等等。


不知電暈,但谷歌搜索the docs for newText則可能是有錯誤的參數(你不及格的字體)。

我可以張貼的所有代碼

越少,你張貼越好,因爲這意味着你已經通過如上圖所示,以嘗試找出問題的步驟了。十次中有九次,這樣做會自行解決問題。