AS3 - 使用If语句拖动到下一个场景。
问题描述:
我正在制作一款互动游戏 - 目前为止我已经有了这段代码。 drop1是硬币,用户将其放入target1(盒子)中,一旦完成,他们就可以在下一个场景中观看视频播放。当drop1(硬币)滴到框中可以看到硬币然后消失AS3 - 使用If语句拖动到下一个场景。
//Array to hold the target instances, the drop instances,
//and the start positions of the drop instances.
var hitArray:Array = new Array(hitTarget1);
var dropArray:Array = new Array(drop1);
var positionsArray:Array = new Array();
//This adds the mouse down and up listener to the drop instances
//and add the starting x and y positions of the drop instances
//into the array.
for (var i:int = 0; i < dropArray.length; i++) {
dropArray[i].buttonMode = true;
dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);
positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
}
//This drags the object that has been selected and moves it
//to the top of the display list. This means you can't drag
//this object underneath anything.
function mdown(e:MouseEvent):void {
e.currentTarget.startDrag();
setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
}
//This stops the dragging of the selected object when the mouse is
//released. If the object is dropped on the corresponding target
//then it get set to the x and y position of the target. Otherwise
//it returns to the original position.
function mUp(e:MouseEvent):void {
var dropIndex:int = dropArray.indexOf(e.currentTarget);
var target:MovieClip = e.currentTarget as MovieClip;
target.stopDrag();
if (target.hitTestObject(hitArray[dropIndex])) {
target.x = hitArray[dropIndex].x;
target.y = hitArray[dropIndex].y;
drop1.visible = false;
}else{
target.x = positionsArray[dropIndex].xPos;
target.y = positionsArray[dropIndex].yPos;
}
}
现在...我想要的代码知道当用户在框中已经下降了硬币如果用户已他们可以观看视频,但如果他们将硬币放入盒中,则只能观看视频。我如何编码?
请大家帮忙。
谢谢
答
如果你还在苦苦挣扎,你随时可以尝试阅读说明书..?我怀疑这就是为什么你迄今还没有答案。在帧/场景之间旅行需要gotoAndPlay或gotoAndStop。检查:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndPlay()
看场景跳转代码的例子二。它说:“介绍”(帧标签)也没关系,只需使用一个号码,但场景的名称必须..如:
mc1.gotoAndPlay("intro", "Scene 12");
或在您的情况类似下面(假设你已经将其命名为scene_video)
if (target.hitTestObject(hitArray[dropIndex])) {
target.x = hitArray[dropIndex].x;
target.y = hitArray[dropIndex].y;
drop1.visible = false;
gotoAndStop(1, "scene_video"); }
我再次假设您的视频播放器在该场景的第1帧,因此在那里停止允许用户有机会观看视频播放器。
谢谢你的帮助 – sjb 2013-06-18 10:11:44