我正在创造一个差异游戏的点,此刻,当你点击差异时,两张图片上都会出现一个框以突出显示差异。单击正确区域时使用鼠标事件将出现该框。
我现在想添加一个点击计数器,这样当找到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;
}
答案 0 :(得分: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();
}