0

我正在创建一个差异游戏,目前,当您单击差异时,两张图片上都会出现一个框以突出显示差异。单击正确区域时使用鼠标事件,将出现该框。

我现在想添加一个点击计数器,所以当发现 5 个差异时,它将进入下一个场景(下一个级别) 我该怎么做?

但我也希望游戏有 3 条生命......所以玩家不能只点击屏幕上的任何地方来查找差异(作弊!).. 所以每次玩家点击鼠标并减去生命时它都会计数屏幕..然后去另一个场景说-“你输了”。

点击次数 =

  • 下一级
  • 生活

我会很感激任何帮助,

谢谢!

我的代码如下:(在 Flash 中使用 AS3)

   //Adds an event listener to the button component with the mouse click event.
//eyes
eyebox.addEventListener(MouseEvent.CLICK, showObject);
eyebox1.addEventListener(MouseEvent.CLICK, showObject);
one.addEventListener(MouseEvent.CLICK, showObject);

//skull 
skullbox.addEventListener(MouseEvent.CLICK, showObject2);
skullbox1.addEventListener(MouseEvent.CLICK, showObject2);
two.addEventListener(MouseEvent.CLICK, showObject2);

//cuffs
cuffbox.addEventListener(MouseEvent.CLICK, showObject3);
cuffbox1.addEventListener(MouseEvent.CLICK, showObject3);
three.addEventListener(MouseEvent.CLICK, showObject3);

//Initially disable the show button.

//eyes
showeye.enabled = true;
showeye1.enabled = true;
eyebox.visible = false;
eyebox1.visible = false;
one.visible = false;

//skull
showskull.enabled = true;
showskull1.enabled = true;
skullbox.visible = false;
skullbox1.visible = false;
two.visible = false;

//cuffs
showcuffs.enabled = true;
showcuffs1.enabled = true;
cuffbox.visible = false;
cuffbox1.visible = false;
three.visible = false;



//Adds an event listener to the button component with the mouse click event.

showeye.addEventListener(MouseEvent.CLICK, showObject);
showeye1.addEventListener(MouseEvent.CLICK, showObject);

showskull.addEventListener(MouseEvent.CLICK, showObject2);
showskull1.addEventListener(MouseEvent.CLICK, showObject2);

showcuffs.addEventListener(MouseEvent.CLICK, showObject3);
showcuffs1.addEventListener(MouseEvent.CLICK, showObject3);



//This function show the movie clip, and disables the show button.
function showObject(event:MouseEvent):void {
eyebox.visible = true;
eyebox1.visible = true;
one.visible = true;
showeye.enabled = true;
showeye1.enabled = true;

}

function showObject2(event:MouseEvent):void {
skullbox.visible = true;
skullbox1.visible = true;
two.visible = true;
showskull.enabled = true;
showskull1.enabled = true;

}

function showObject3(event:MouseEvent):void {
cuffbox.visible = true;
cuffbox1.visible = true;
three.visible = true;
showcuffs.enabled = true;
showcuffs1.enabled = true;

}
4

1 回答 1

0

我认为甚至没有必要为每个对象添加事件侦听器。在我看来,您可以先将一个听众添加到整个画面中:

wholePicture.addEventListener(MouseEvent.CLICK, clickListener);

然后在 clickListener 中查看用户是否单击了您的对象或者他/她是否错过了:

function clickListener(e:MouseEvent):void {
   if(showEye.hitTestPoint(e.x, e.y) || showeye1.hitTestPoint(e.x, e.y)){
      showObject();
      ++NextLevelCounter;
   }else if(showSkull.hitTestPoint(e.x, e.y) || showSkull1.hitTestPoint(e.x, e.y)){
      showObject2();
      ++NextLevelCounter;
   }else if(cuffbox.hitTestPoint(e.x, e.y) || cuffbox1.hitTestPoint(e.x, e.y)){
      showObject3();
      ++NextLevelCounter;
   }else{
      --LivesCounter;
   }
   if(NextLevelCounter > 5)
      goToNextLevel();
   if(LivesCounter == 0)
      loose();
}
于 2013-06-18T11:36:50.613 回答