为什么单击我的动画片段如此难?

时间:2013-11-26 02:47:05

标签: actionscript-3 flash

我在一个数组中有一个影片剪辑(tempEnemyA)(enemiesA)。这些敌人倒下,玩家通过点击它们来杀死它们。得分越高=敌人下落的速度越快。但是出于某种原因,当舞台上有很多敌人时,他们开始变得非常难以点击。这是tempEnemyA中的代码:

import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.motion.Animator;
import flash.events.*;
import flash.utils.setTimeout;

this.addEventListener(MouseEvent.CLICK, killM);
this.dead3 = false;

function killM(event:MouseEvent):void 
{
    this.dead3=true;
    this.mouseChildren=false
    gotoAndPlay(31);
    this.removeEventListener(MouseEvent.CLICK, killM);
  flash.utils.setTimeout(removeSelfM,2000);

}

function removeSelfM():void
{
    this.parent.removeChild(this);
    this.addEventListener(MouseEvent.CLICK, killM);
}

this.dead3在舞台层内激活此条件:

if (tempEnemyA.dead3) 
    {
        scoreA++;
        scoreA++;
        AntLevel.scoreA_txt.text = String(scoreA);
        enemiesA.splice(g,1);
    } 

总的来说,这是产生敌人的整个代码:

function makeEnemiesA():void
{
    var chance:Number = Math.floor(Math.random() * 150);
    if (chance <= + levelA)
    {


        //Make sure a Library item linkage is set to Enemy...
        tempEnemyA = new Mosquito();
        tempEnemyA.speed = 2
        //Math.random(); gets a random number from 0.0-1.0
        tempEnemyA.x = Math.round(Math.random() * 550);
        addChild(tempEnemyA);
        enemiesA.push(tempEnemyA);
        tempEnemyA.speed = enemyBaseSpeed3 + ((levelA - 1) * speedLevelInc3);
         if (tempEnemyA.speed > MAX_SPEED3)
         {
        tempEnemyA.speed = MAX_SPEED3;

        }
    }
}

function moveEnemiesA():void
{
    var tempEnemyA:MovieClip;

    for (var g:int =enemiesA.length-1; g>=0; g--)
    {

     tempEnemyA=enemiesA[g];
    if (tempEnemyA.dead3) 
    {
        scoreA++;
        scoreA++;
        AntLevel.scoreA_txt.text = String(scoreA);
        enemiesA.splice(g,1);
    } 
         else // Enemy is still alive and moving across the screen
        {
            //rotate the enemy between 10-5 degrees
            tempEnemyA.rotation += (Math.round(Math.random()*.4));
            //Find the rotation and move the x position that direction
            tempEnemyA.x -=  (Math.sin((Math.PI/180)*tempEnemyA.rotation))*tempEnemyA.speed;
            tempEnemyA.y +=  (Math.cos((Math.PI/180)*tempEnemyA.rotation))*tempEnemyA.speed;
            if (tempEnemyA.x < 12)
            {
                tempEnemyA.x = 12;
            }
            if (tempEnemyA.x > stage.stageWidth - offset2)
            {
                tempEnemyA.x = stage.stageWidth - offset2;
            }
            if (tempEnemyA.y > stage.stageHeight)
            {
                removeEnemyA(g);
                livesA--;
                AntLevel.livesA_txt.text = String(livesA);
            }
        }
    }
}

0 个答案:

没有答案