我正在尝试创建一个类似Tap Tap的游戏,除了下落的物体被随机化之外。我现在遇到的问题是如果随机对象再次被选中(在它移动之前),它的位置将被重置(这也意味着两个相同的对象不会出现在我不想要的屏幕中)我想出了一个办法解决这个问题,我应该能够创建一个摘录的动画片段的副本,但我迷路了。帮帮我?生成下降的随机对象在阵列中进行选择
此外,我是新来的闪存。如果您有建议/建议,请告诉我! 谢谢你,祝你有美好的一天。
var notes:Array = new Array(NGood1,NGood2,NGood3,NGood4,NGood5,NBad1,NBad2,NBad3,NBad4,NBad5);
var pos1:int;
var pos2:int;
var pos3:int;
pos1 = (stage.stageWidth/3) -100;
pos2 = (stage.stageWidth/2) -100;
pos3 = ((stage.stageWidth/3) *2) -100;
var timerN:Timer = new Timer(1000,120);
timerN.addEventListener(TimerEvent.TIMER, timerhandler);
timerN.start();
var secondsN:Number = 1;
function timerhandler(event:TimerEvent)
{
//trace("Seconds elapsed: " + seconds);
SpawnNote(null);
secondsN++;
}
function SpawnNote(event:Event):void
{
var spawn:int;
var rpos:int;
spawn = int(Math.random() * notes.length);
rpos = int(Math.random() * 3) + 1;
var note:MovieClip = new MovieClip();
note = notes[spawn];
addChild(note);
if (rpos ==1)
{
note.x = pos1;
}
else if (rpos==2)
{
note.x = pos2;
}
else if (rpos==3)
{
note.x = pos3;
}
note.y = -20;
note.addEventListener(Event.ENTER_FRAME, MoveNote);
function MoveNote(event:Event):void
{
note.y += 5;
if (note.y >= stage.stageHeight - 50)
{
note.addEventListener(Event.ENTER_FRAME, StopNote);
function StopNote(event:Event):void
{
note.removeEventListener(Event.ENTER_FRAME, MoveNote);
//do more
}
}
}
}
谢谢你。我设法清理了一下我的代码。 但我得到错误与var注:MovieClip =新笔记[spawn](); 我是否需要删除时间线中的动画片段? 这里是我的代码:http://pastebin.com/3a9acu1X –
是的,你需要,因为'NGood1'现在不是对象名称,而是类名称。比方说,你画一个新的影片剪辑并保存到图书馆,然后有一个复选框“Export for Actionscript”,你检查它并输入类名,然后你可以在你的'notes'数组中使用它。此外,你再次试图在你的'btimerhandler'函数中依赖局部变量,因为你的'bsecondsN'位于**函数**'MoveNote'内,而不是在主时间轴代码中。请注意那些花括号,这些表示物体的可用性和它们的寿命。 – Vesper
您应该在'MoveNote'代码之外定位您的'btimerhandler'监听器,就像我使用与'SpawnNote'相关的'MoveNote'一样。事实上,你似乎想让你的笔记在“地面”放下3秒钟然后消失,但是如果同时有几个地面在地面上,你能告诉我什么笔记要被删除吗? – Vesper