我只是ActionScript中的新手,我们需要使用ActionScript 2制作游戏。
所以,我有三个按钮的主场景,当我按下其中一个按钮时,它将进入迷你游戏。当玩家成功进入迷你游戏时,它将返回主场景并且禁用按下的按钮。现在,我只能按下按钮被禁用,它不会进入迷你游戏的场景。谁能帮我?
这里是代码:
stop();
var places:Array = [flood_btn, earthquake_btn, landslide_btn];
var pressedbtn;
function Dplaces():Void {
pressedbtn.enabled = true;
this.enabled = false;
}
for (ctr = 0; ctr < places.length; ctr++) {
places[ctr].onRelease = Dplaces;
}
答案 0 :(得分:0)
在你的代码中,我没有看到你如何从主要场景转到其他场景,当然你必须明白,每次你回到主场景时,每件事都会被初始化,所以你有例如,使用像这样的全局变量来处理它:
stop();
// verify if this is our first run, so create our global pressed_btn var
// otherwise, pressed_btn contains the current pressed button index
if (pressed_btn == undefined)
{
_global.pressed_btn = -1;
}
var places:Array = [flood_btn, earthquake_btn, landslide_btn];
// init our buttons and disable, if we have, the current pressed one
for (ctr = 0; ctr < places.length; ctr++)
{
var btn:Button = places[ctr];
if (ctr != pressed_btn)
{
// we add the index attribut to identify our button when it's pressed to go to the appropriate scene
btn['index'] = ctr;
btn.onRelease = Dplaces;
} else {
// if we have a pressed button, disable it
btn.enabled = false;
}
}
function Dplaces():Void {
// save the current pressed button index
_global.pressed_btn = this.index;
switch (this.index)
{
case 0 :
gotoAndStop("game1", 1);
break;
case 1 :
gotoAndStop("game2", 1);
break;
case 2 :
gotoAndStop("game3", 1);
break;
}
}
希望可以提供帮助。