我正在尝试在 Flash 中制作原始游戏。我正在使用 AS3 来构建它。到目前为止,我编写的所有代码都运行良好。到目前为止,我只有 3 帧。但是,我已经准备好继续前进,所以我添加了第四帧。但是,当我测试动画时,它会从第 2 帧跳到第 4 帧。我在第 3 帧中放置了一个跟踪,以查看 Flash 是否正在运行它,并且跟踪执行跟踪,所以我知道 Flash 并没有完全忽略第 3 帧. 但是,我stop();
在第 3 帧的末尾有一个,我有一个stop();
在第 4 帧上。所以,我不确定为什么要跳过第 3 帧。游戏没有任何补间动画或实际动画,所以它不应该是那种东西。唯一的交互是点击点。我已将所有 4 个框架的代码放在下面(我不确定这是否令人不悦。如果是,请告诉我,我会删除它,但我之所以放它是因为它看起来可能有帮助)。我还上传了一个指向我的 .FLA 文件的链接,以防有人想查看整个内容。
第一帧:
import flash.events.MouseEvent;
var dotList = new Array(); var level:int = 10; var invisoDotList = new Array();
var loop:int;
for(loop = 0; loop < level; loop++)
{
var dot:Dot = new Dot();
var invisoDot:InvisoDot = new InvisoDot();
var tester:Boolean = true;
var xval:int = Math.floor(Math.random()*(1+520))+14;
var looper:int = 0;
while(looper < dotList.length)
{
if(Math.abs(xval - dotList[looper].x) > 30)//minimum spacing
{
looper++;
}
else
{
looper = 0;
xval = Math.floor(Math.random()*(1+520))+14;
}
}
dot.x = xval;
dot.y = 187;
invisoDot.x = xval;
invisoDot.y = 187;
invisoDot.alpha = 0;
dotList[loop] = dot;
invisoDotList[loop] = invisoDot;
addChild(invisoDot);
addChild(dot);
}
//trace(dotList); test to ensure that dots are added to the array
button.addEventListener(MouseEvent.CLICK, hideDots);
function hideDots(e:MouseEvent)
{
for(var loop:int = 0; loop < dotList.length; loop++)
{
dotList[loop].alpha = 0;//make dots disappear
}
nextFrame();
}
stop();
第 2 帧:
import flash.events.MouseEvent;
button.addEventListener(MouseEvent.CLICK, next);
function next(e:MouseEvent)
{
nextFrame();
}
stop();
第 3 帧:
import flash.events.MouseEvent;
removeChild(button);
var clicks:int = -1;
//trace(dotList.length);
stage.addEventListener(MouseEvent.CLICK, clickCount);
for(var loopvar:int = 0; loopvar < dotList.length; loopvar++)
{
//trace("loop");
dot = dotList[loopvar];
invisoDot = invisoDotList[loopvar];
dot.addEventListener(MouseEvent.CLICK, onClick);
invisoDot.addEventListener(MouseEvent.CLICK, onClick);
//trace("event");
}
//trace(dotList.length);
function onClick(e:MouseEvent)
{
//e.currentTarget.alpha = .5;
for(var hitcheck:int = 0; hitcheck < dotList.length; hitcheck++)
{
if(dotList[hitcheck].x == e.currentTarget.x)
{
dotList[hitcheck].alpha = 1;
}
}
//trace("check");
}
function clickCount(e:MouseEvent)
{
clicks++;
//trace(clicks);
var numChanged:int = 0;
for(var index:int = 0; index < dotList.length; index++)//check whether the user has gotten all the dots
{
if(dotList[index].alpha == 1)
{
numChanged++;
}
}
if(numChanged == level)//if the user has gotten all the dots
{
trace("next screen for sucess");
trace(clicks);
}
else if((clicks - numChanged) >= 2)//this ends the session as soon as 2 mistakes are made
{
trace("next screen for failed number of clicks");
trace(clicks);
}
/*else if((clicks - level) >= 2)//if the user has made too many mistakes. This ends the session after the maximum number of tries have been used
{
trace("next screen too many clicks");
trace(clicks);
}*/
}
trace("end");
stop();
第 4 帧:
stop();
.FLA 文件链接:https ://www.dropbox.com/s/x1vim49tnz227id/Game.fla
如果我在这个问题中使用的任何约定是错误的或不赞成,请告诉我,我会纠正它们。距离我上次在 StackOverflow 上发帖已经一年多了。