0

我正在制作一个互动游戏——到目前为止我有这个代码。其中 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;

  }
  }

现在...我希望代码知道用户何时将硬币放入盒子中,如果用户有,则他们可以观看视频,但如果他们将硬币放入盒子中,则只能观看视频。我该如何编码?

请帮忙。

谢谢你

4

1 回答 1

0

如果您仍在苦苦挣扎,您可以随时尝试阅读手册..?我怀疑这就是为什么你到目前为止还没有答案。在帧/场景之间移动需要 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 帧,因此停在那里可以让用户有机会观看视频播放器。

于 2013-04-11T03:07:59.140 回答