随机选择3张图片之间

嗨,我想随机选择三张图片中的一张'BCloud1.png,BCloud2.png,BCloud3.png'。有什么最好的方式来做到这一点,我尝试添加了一个math.random(1, 3);,如:star4.imgpath = "BCloud .. math.random(1, 3); .. .png";,但这并不起作用。

-- 在'BCloud1.png,BCloud2.png,BCloud3.png'中随机选择

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

这个问题有什么简单的解决方法吗?

点赞
用户1190388
用户1190388

你的语句有一个小的语法错误。应该改为:

star4.imgpath = "BCloud"..tostring(math.random(1, 3))..".png";
2013-02-27 21:38:37