我正在尝试创建一个小游戏(更多的是学习如何做而不是制作一个引人入胜的游戏)。可以这样恢复:用户在菜单中选择一个建筑物并将其放置在舞台上。当点击新建的建筑时,她/他可以选择升级它。(对于那些玩《部落冲突》之类的游戏的人,这就是我想要做的)。我有我的菜单,可以毫无问题地放置建筑物,但我无法点击它们。这是我的代码的开头:
var build:int=0; //variable that defines which building to place on stage
menuBuilding.house.addEventListener(MouseEvent.CLICK, fnChooseHouse); //when click on House in Building Menu
function fnChooseHouse (e:Event):void{
build = 1; //building to place is a House.
}
city.addEventListener(MouseEvent.CLICK, mouseClickEvent);
function mouseClickEvent(e: MouseEvent): void {
if (build == 0) { //if building not chosen, do nothing
return
} else if (build == 1) { // if building is a house
var house1: house = new house();
addChild(house1); //add instance of the house
house1.x = stage.mouseX;
house1.y = stage.mouseY; // place the house where I clicked
build = 0; //reset the variable.
house1.mouseChildren=true; //allow instance of house to be clicked.
}
};
我的问题是会有很多房子(和其他建筑物)。我试图命名它们并将它们推送到一个数组中(所以我可以使用 for each...in 循环访问它们),但它不起作用。
有人有想法吗?(顺便说一句,我还在学习 AS3,所以我还没有使用外部 .as 文件,仍在时间线上)。提前致谢 :)