2013-02-27 100 views
0

嗨,我試圖在3張圖片之間隨機選擇'BCloud1.png,BCloud2.png,BCloud3.png' 這樣做的最佳方式是什麼,我嘗試添加math.random(1, 3);,如: star4.imgpath = "BCloud .. math.random(1, 3); .. .png";從3張圖片中隨機選擇

但不工作

-- select randomly between BCloud1.png, BCloud2.png, BCloud3.png 

    local star4 = {} 
    star4.imgpath = "BCloud1.png"; 
    star4.movementSpeed = 16000; 
    table.insert(starTable, star4); 

任何簡單的辦法解決這個問題?

回答

4

您的語句有一點語法錯誤。它應該是:

star4.imgpath = "BCloud"..tostring(math.random(1, 3))..".png"; 
+0

創建一個可以生成和插入星號的函數。我們稱之爲myFunc()。然後,添加一個'timer.performWithDelay(2000,myFunc)' – hjpotter92 2013-02-27 21:52:51