我正在制作互动游戏 - 到目前为止我已经有了这个代码。其中drop1是一枚硬币而用户将其放入target1(盒子)中,一旦完成,他们就可以在下一个场景中观看视频播放。如你所知,当drop1(硬币)掉落到盒子上时,硬币就会消失
//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;
}
}
现在......我希望代码知道用户何时将硬币放入盒子中,如果用户有,他们就可以观看视频,但只有当他们将硬币放入盒子中时才能观看视频。我怎么能这样编码?
请帮忙。
谢谢
答案 0 :(得分:0)
如果您还在苦苦挣扎,可以随时尝试阅读手册。我怀疑这就是你到目前为止没有答案的原因。在帧/场景之间旅行需要gotoAndPlay或gotoAndStop。检查:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndPlay()
查看场景跳转代码的示例二。在哪里说&#34;介绍&#34; (框架标签)可以只使用一个数字,但场景必须有名称......例如:
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帧,因此停在那里可让用户有机会观看视频播放器。