Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何检查多个符号的冲突_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 如何检查多个符号的冲突

Actionscript 3 如何检查多个符号的冲突,actionscript-3,flash,Actionscript 3,Flash,我想知道是否可以通过实例名而不是单独的mc名来检查冲突。我有大约150-200个物体(吃豆人游戏中的点),我需要检查碰撞情况,并希望能有效地进行。谢谢 如果您有名为dots的实例和一个播放器,您可以执行以下操作: //a var to hold each loop iteration's dot for convenience var tmpDot:DisplayObject; //loop 200 times from 1 - 200 for(var i:int=1;i<= 200;i

我想知道是否可以通过实例名而不是单独的mc名来检查冲突。我有大约150-200个物体(吃豆人游戏中的点),我需要检查碰撞情况,并希望能有效地进行。谢谢

如果您有名为dots的实例和一个播放器,您可以执行以下操作:

//a var to hold each loop iteration's dot for convenience
var tmpDot:DisplayObject;

//loop 200 times from 1 - 200
for(var i:int=1;i<= 200;i++){
    //getChildByName gets an instance from a string, in this case dot plus i (i is the current iteration number)
    tmpDot = getChildByName("dot" + i);

    //check if the dot exists and is hitting the player
    if(tmpDot && tmpDot.hitTestObject(player)){
        //hit a dot, do something here like remove the dot
        removeChild(tmpDot);
        //increment points etc.

        //if there's no possibility of the player hitting more than one dot at a time, then for efficiency you should break out of this loop
        break;
    }
}
//YOU PROBABLY WANT TO DO THIS EITHER EVERY FRAME, OR WHENEVER THE PLAYER MOVES

//flag to see if all dots are eaten
var allEaten:Boolean = true;
var tmpDot:Dot;

for(var i:int=0;i<allDots.length;i++){
    tmpDot = allDots[i];

    //.... same as the top code example at this point
    if(tmpDot && tmpDot.hitTestObject(player)){
        removeChild(tmpDot);
        //do anything else you need to do when a dot is eaten

        //if we've already determined that we haven't eaten all the dots, then break the loop
        if(!allEaten) break;
    }

    //if a dot has a parent, then they haven't been all eaten
    if(tmpDot.parent){
        allEaten = false;
    }
}
现在,您可以像这样进行命中测试:

//a var to hold each loop iteration's dot for convenience
var tmpDot:DisplayObject;

//loop 200 times from 1 - 200
for(var i:int=1;i<= 200;i++){
    //getChildByName gets an instance from a string, in this case dot plus i (i is the current iteration number)
    tmpDot = getChildByName("dot" + i);

    //check if the dot exists and is hitting the player
    if(tmpDot && tmpDot.hitTestObject(player)){
        //hit a dot, do something here like remove the dot
        removeChild(tmpDot);
        //increment points etc.

        //if there's no possibility of the player hitting more than one dot at a time, then for efficiency you should break out of this loop
        break;
    }
}
//YOU PROBABLY WANT TO DO THIS EITHER EVERY FRAME, OR WHENEVER THE PLAYER MOVES

//flag to see if all dots are eaten
var allEaten:Boolean = true;
var tmpDot:Dot;

for(var i:int=0;i<allDots.length;i++){
    tmpDot = allDots[i];

    //.... same as the top code example at this point
    if(tmpDot && tmpDot.hitTestObject(player)){
        removeChild(tmpDot);
        //do anything else you need to do when a dot is eaten

        //if we've already determined that we haven't eaten all the dots, then break the loop
        if(!allEaten) break;
    }

    //if a dot has a parent, then they haven't been all eaten
    if(tmpDot.parent){
        allEaten = false;
    }
}
//您可能希望在每一帧或播放器移动时执行此操作
//标记以查看是否所有圆点都被吃掉
var allEaten:Boolean=true;
var-tmpDot:Dot;

对于(var i:int=0;i如果您有名为dots的实例和一个播放器,您可以执行以下操作:

//a var to hold each loop iteration's dot for convenience
var tmpDot:DisplayObject;

//loop 200 times from 1 - 200
for(var i:int=1;i<= 200;i++){
    //getChildByName gets an instance from a string, in this case dot plus i (i is the current iteration number)
    tmpDot = getChildByName("dot" + i);

    //check if the dot exists and is hitting the player
    if(tmpDot && tmpDot.hitTestObject(player)){
        //hit a dot, do something here like remove the dot
        removeChild(tmpDot);
        //increment points etc.

        //if there's no possibility of the player hitting more than one dot at a time, then for efficiency you should break out of this loop
        break;
    }
}
//YOU PROBABLY WANT TO DO THIS EITHER EVERY FRAME, OR WHENEVER THE PLAYER MOVES

//flag to see if all dots are eaten
var allEaten:Boolean = true;
var tmpDot:Dot;

for(var i:int=0;i<allDots.length;i++){
    tmpDot = allDots[i];

    //.... same as the top code example at this point
    if(tmpDot && tmpDot.hitTestObject(player)){
        removeChild(tmpDot);
        //do anything else you need to do when a dot is eaten

        //if we've already determined that we haven't eaten all the dots, then break the loop
        if(!allEaten) break;
    }

    //if a dot has a parent, then they haven't been all eaten
    if(tmpDot.parent){
        allEaten = false;
    }
}
现在,您可以像这样进行命中测试:

//a var to hold each loop iteration's dot for convenience
var tmpDot:DisplayObject;

//loop 200 times from 1 - 200
for(var i:int=1;i<= 200;i++){
    //getChildByName gets an instance from a string, in this case dot plus i (i is the current iteration number)
    tmpDot = getChildByName("dot" + i);

    //check if the dot exists and is hitting the player
    if(tmpDot && tmpDot.hitTestObject(player)){
        //hit a dot, do something here like remove the dot
        removeChild(tmpDot);
        //increment points etc.

        //if there's no possibility of the player hitting more than one dot at a time, then for efficiency you should break out of this loop
        break;
    }
}
//YOU PROBABLY WANT TO DO THIS EITHER EVERY FRAME, OR WHENEVER THE PLAYER MOVES

//flag to see if all dots are eaten
var allEaten:Boolean = true;
var tmpDot:Dot;

for(var i:int=0;i<allDots.length;i++){
    tmpDot = allDots[i];

    //.... same as the top code example at this point
    if(tmpDot && tmpDot.hitTestObject(player)){
        removeChild(tmpDot);
        //do anything else you need to do when a dot is eaten

        //if we've already determined that we haven't eaten all the dots, then break the loop
        if(!allEaten) break;
    }

    //if a dot has a parent, then they haven't been all eaten
    if(tmpDot.parent){
        allEaten = false;
    }
}
//您可能希望在每一帧或播放器移动时执行此操作
//标记以查看是否所有圆点都被吃掉
var allEaten:Boolean=true;
var-tmpDot:Dot;

对于(var i:int=0;iYes当然可能。我希望你不会一直给每个点命名
dot1
…等等,直到
dot200
。你是如何将它们添加到舞台上的?我的库中有一个带有实例点的mc。@TaylorSwiftYes当然可能。我希望你不会一直给每个点命名
dot1
…等等,直到
dot200
)>。你如何将它们添加到舞台上?我的库中有一个带有实例点的mc。@Taylorswift这实际上是最大的帮助,非常感谢+1,但我很难理解如何将它们添加到阵列中,无论如何,谢谢!这实际上是最大的帮助,非常感谢+1,但我很难理解如何将它们添加到阵列中我想了解一下如何将它们添加到阵列中,无论如何,谢谢!