0

以下の私のコードを見てください。ボールがゴールエリアに当たらないたびにvarミスを1増やす必要があります(これはPK戦です)が、問題は何度も増えるということです。これは変数値のトレースを行った後にメッセージを出力して、次のことを理解できるようにします。

それは失敗です11それは失敗です22それは失敗です33それは失敗です44それは失敗です55それは失敗です66それは失敗です77それは失敗です88それは失敗です98それは失敗です1010など、私のコードはこれであり、必要な結果に影響を与える行は、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);


}

 }

良い仲間がこれをチェックするのに時間がかかるなら、私は本当に感謝します。私がより良いプログラマーを手に入れたら、それを必要とするすべての人を助けることを約束します。

再度、感謝します!

4

1 に答える 1

0

コードを変更して、出力を再度提供できますか?

trace("It's a fail for barrier3", misses)
trace("It's a fail for barrier2", misses) and so on.
于 2012-08-16T03:05:05.957 に答える