0
A
回答
1
如下你可以這樣做:
--Create your quote array with quote strings
local myQuoteArray = {"first quote",
"second quote",
"third quote"}
--Display a label and postion it on the screen --
local myLabel = display.newText("Initial string",0,0,nil,14)
myLabel.x = display.contentWidth/2
myLabel.y = display.contentHeight/2
myLabel:setTextColor(255)
--Function for restting the label with any random string from 'myQuoteArray'
local function setLabelString()
--Take any string from the array within its range/count (#myQuoteArray)
--And reset the label/text with the new string/quote
myLabel.text = myQuoteArray[math.random(#myQuoteArray)]
end
Runtime:addEventListener("tap",setLabelString)
保持編碼.................... :)
+0
感謝它的工作完美 – user3425220
0
您可以通過這三個引號定義表:
local quotes= {}
quotes[1] = "first quote"
quotes[2] = "second quote"
quotes[1] = "third quote"
創建標籤
local label=display.newText{
text="",
x=0,y=100,
width=100,height=40,
font=native.systemFrom,
fontSize=16
}
初始化隨機數發生器
math.randomseed(os.time())
然後創建一個按鈕:
local handleRelease = function(event)
local index=math.random(3)
local quote=quotes[index]
label.text = quote
end
local button = widget.newButton{
x=0, y=0,
width=100, height=40,
label="Press me",
onRelease = handleRelease
}
你需要調用它從場景中進行顯示。
相關問題
- 1. 我怎樣才能通過隨機
- 2. 隨機報價生成器
- 3. 我怎樣才能電報機器人
- 4. 我們怎樣才能生成rspec的
- 5. 我怎樣才能生成一個PDF
- 6. 我怎樣才能生成@Enumerated與hibernate.reveng
- 7. 我怎樣才能隨機生成一個字符串的兩個值之一?
- 8. 我怎樣才能生成多個隨機數字在沒有相同的PHP
- 9. SpriteKit:我怎樣才能讓我的HUD跟隨我的相機?
- 10. 使JavaScript隨機報價生成器每天生成一個報價
- 11. 我的win32 emacs隨機崩潰。我怎樣才能調試呢?
- 12. 我怎樣才能獲得價值? Odoo
- 13. 我怎樣才能grep字符串與報價和colopn
- 14. 隨機數字生成器javascript。我怎樣才能防止它刷新時生成一個新的號碼?
- 15. 我怎樣才能用Clang生成未使用的聲明?
- 16. 我怎樣才能扭曲一組隨機數的分佈?
- 17. 我怎樣才能使PHP
- 18. 怎樣才能生成一輪排列
- 19. 我怎樣才能
- 20. 我怎樣才能
- 21. 我怎樣才能
- 22. 我怎樣才能
- 23. 我怎樣才能使用MVC3生成id(爲「屬性」設置)?
- 24. Python - 我怎樣才能更簡潔地使用生成器?
- 25. 我怎樣才能使用xmlTextWriter在.ashx中爲myXMLHttpRequest.responseXML生成xml
- 26. 我們怎樣才能生成使用一個表MySQL表
- 27. 我怎樣才能殺死使用system()生成子進程?
- 28. 我怎樣才能完成這個隨機的複雜工作? C#
- 29. 我怎樣才能讓按鈕隨機點擊
- 30. 我怎樣才能關機CompletionService
你是什麼意思「引用」? – Dai
你的意思是像[財富](http://en.wikipedia.org/wiki/Fortune_%28Unix%29)? –