我试图在我正在制作的游戏中使用数组进行清点。将变量与数字结合起来
我需要的是一些具有可变结合的方式,这样的事情:
itemBoxNumber = "itemBox" + currentItemBox;
//In this case itemBoxNumber would say itemBox1
,我可以用它来代替itemBox1。
function itemsMenuUpdate():void
{
for (var a:int = 0; a<maxInventory; a++){
var currentItemBox:Number = 1;
if(~inventory.indexOf("Potion")){
mainMenu.itemBox1.gotoAndStop("Potion");
}
if(~inventory.indexOf("Hi-Potion")){
mainMenu.itemBox1.gotoAndStop("Hi-Potion");
}
}
}
我只能找到AS2工作方法。任何帮助与此赞赏。
您可以使用向量(或阵列)来存储你需要访问的所有对象,而t母鸡使用currentItemBox作为访问Vector中特定对象的索引。 – jpop