你能看看我下面的代码吗,每次球没有击中球门区域(这是一场点球大战)时,我需要将 var miss 增加 1,但问题是它增加了很多倍,这是跟踪变量值后输出消息,以便您有一个想法:
失败 1 1 失败 2 2 失败 3 3 失败 4 4 失败 5 5 失败 6 6 失败 7 7 失败 8 8 失败 9 9 失败 10 10依此类推,我的代码是这样的,我很确定影响所需结果的行是 stage.addEventListener(Event.ENTER_FRAME, onEnter); 你能给我一些关于如何解决这个问题的建议吗?当在 moveBall 函数中移动时,可能会尝试另一种方式来移动球?我从你们那里得到了很多帮助,很抱歉让我如此烦人,只是我还是个新手,在我的代码和我迄今为止收集的想法之间的某些点上卡住了。这是我的代码
import flash.events.Event;
import flash.ui.Mouse;
import flash.geom.Point;
import flash.events.MouseEvent;
var misses:int= 0;//Here the var used trying to put the game over when player misses 3 shoots
var cursor:MovieClip; // mouse will be converted to a cursor (aim) which is the spot ball must follow
var nowX:Number; ;// will be used to move the ball
var nowY:Number;// will be used to move the ball
var isUpdating:Boolean = false; // will be used to control mouse events and other later on
var isClipSync:Boolean = false; // will be used to control mouse events and other later on
const START_BALL_POINT:Point = new Point(296,353); // returning the ball to original positions
function initializeGame():void
{
cursor = new Cursor();
addChild(cursor);
cursor.enabled = false;
//Mouse.hide();
stage.addEventListener(MouseEvent.CLICK, dragCursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onCursorMove);
}
function onCursorMove(e:MouseEvent):void
{
cursor.x = mouseX;
cursor.y = mouseY;
}
function onEnter(e:Event):void
{
isUpdating= true;
if(pateador_mc.currentFrame == 19)
{
pateador_mc.gotoAndStop(1);
}
//trace(pateador_mc.currentFrame);
//
if(pateador_mc.currentFrame > 11)
isClipSync = true;
moveBall();
}
function dragCursor(event:MouseEvent):void
{
if(isUpdating) return;
trace(isUpdating);
nowX = mouseX;
nowY = mouseY;
pateador_mc.play();
stage.addEventListener(Event.ENTER_FRAME, onEnter);// probably this is causing multiple count of trace events when I try to gather the failed shoots
}
initializeGame();
var mouse=this.Mouse;
var speed:int = 800;
var ease:int = 4;
var gravity:Number = 0.5;
function moveBall()
{
if(!isClipSync) return;
bola.x += 0.2 * (nowX - bola.x);
bola.y += 0.2 * (nowY - bola.y);
if(Math.abs(nowX-bola.x)<1 && Math.abs(nowY-bola.y)<1)
{
stage.removeEventListener(Event.ENTER_FRAME, onEnter);
isUpdating = false;
isClipSync = false;
var timer3:Timer = new Timer(3000,1);
timer3.addEventListener(TimerEvent.TIMER, accionRepetida3);
timer3.start();
function accionRepetida3(e:TimerEvent)
{
bola.x = START_BALL_POINT.x;
bola.y = START_BALL_POINT.y;}
}
if (bola.hitTestObject(goalie))
{
gol_mc.play(); /// All good at this point
red_mc.play();
}
//
else
{
misses++;
trace("It's a fail", misses);
}
}
如果有好朋友花时间检查一下,我将非常感激,我保证当我遇到更好的程序员时,我会帮助所有需要它的人。
再次感谢!