如何对影片剪辑的所有实例进行命中测试 - ACTIONSCRIPT 2

发布于 2025-01-06 11:38:44 字数 1127 浏览 5 评论 0原文

我正在制作一款塔防游戏,并且已经达到了我的塔以适当的间隔发射子弹的程度。但我需要能够删除影片剪辑。例如,如果一座塔发射一颗子弹,它会制作子弹影片剪辑的副本,该副本瞄准特定敌人的副本。但是,我不知道如何配置 hitTest。有没有办法让 hittest 检查从特定对象复制的所有子影片剪辑?

编辑:我添加了这个函数,它每秒执行一次。但由于某种原因,它没有确认点击次数。

function checkHits(){//checks for hits between enemies and bullets
for (var zz = 0; zz < bulletArray.length; zz += 1)//checks for each bullet
{
    for(var yy=0;yy<enemiesArray.length;yy+=1){//checks for each enemy
        trace("enemies loc"+yy+":"+enemiesArray[yy]);
        trace("bullet loc"+zz+":"+bulletArray[zz]);
        if(bulletArray[zz].hitTest(enemiesArray[yy])){
            trace("HIT!");
           removeMovieClip(bulletArray[zz]);
           removeMovieClip(enemiesArray[yy]);
           bulletArray.splice(zz,1);
           bulletArray.splice(yy,1);
           }//end if
    }//end for
}//end for

function dupeCircle()
{
//trace("Dupe circle initiated");
duplicateMovieClip(circlebase, "_root.circle" + circleCount, circleCount);
bulletArray.push("circle" + circleCount);
trace(bulletArray[0]._width);
circleCount += 1;
}

是添加圆圈的对象的代码。

I am making a tower defense game, and have gotten it to the point that my towers shoot bullets at appropriate intervals. But I need to be able to remove the movieclips. For example, if a tower shoots a bullet, it makes a copy of the bullet movieclip, which is aimed at a duplicate of the specific enemy. However, I cannot figure out how to configure the hitTest. Is there any way to gt the hittest to check for all child movieclips duplicated from a specific object?

EDIT: I added this function, which is to execute every second. But for some reason, it does not confirm the hits.

function checkHits(){//checks for hits between enemies and bullets
for (var zz = 0; zz < bulletArray.length; zz += 1)//checks for each bullet
{
    for(var yy=0;yy<enemiesArray.length;yy+=1){//checks for each enemy
        trace("enemies loc"+yy+":"+enemiesArray[yy]);
        trace("bullet loc"+zz+":"+bulletArray[zz]);
        if(bulletArray[zz].hitTest(enemiesArray[yy])){
            trace("HIT!");
           removeMovieClip(bulletArray[zz]);
           removeMovieClip(enemiesArray[yy]);
           bulletArray.splice(zz,1);
           bulletArray.splice(yy,1);
           }//end if
    }//end for
}//end for

}

function dupeCircle()
{
//trace("Dupe circle initiated");
duplicateMovieClip(circlebase, "_root.circle" + circleCount, circleCount);
bulletArray.push("circle" + circleCount);
trace(bulletArray[0]._width);
circleCount += 1;
}

This is the code for the object which adds the circles.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趴在窗边数星星i 2025-01-13 11:38:44

您可以保留一个数组,其中包含要测试的所有影片剪辑,然后循环遍历该数组并检查每个剪辑。因此,每当您向屏幕添加一个时,请将其添加到该数组中。然后,当您想要测试时,测试该数组中的每个人。如果要删除它,请将其从阵列和屏幕中删除。

编辑

这是我在这种情况下想做的事情......

function dupeCircle() 
{    
    //trace("Dupe circle initiated"); 
    bulletArray.push(duplicateMovieClip(circlebase, "_root.circle" + circleCount, circleCount));
    circleCount += 1; 
 }

基本上只需将实际的影片剪辑存储在数组中,然后你就可以做你想做的事情bulletArray[index].hitTest 应该可以正常工作。 (在存储其他数组的实际影片剪辑时也执行相同的操作)

You could keep an array with all of the movieclips you want to test in it and then loop through that array and check each one. So whenever you add one to the screen, add it to that array. Then when you want to test, test everyone in that array. If you want to remove it, remove it from the array and the screen.

EDIT

Here is what I would think to do in this case...

function dupeCircle() 
{    
    //trace("Dupe circle initiated"); 
    bulletArray.push(duplicateMovieClip(circlebase, "_root.circle" + circleCount, circleCount));
    circleCount += 1; 
 }

Basically just store the actual movieclip in the array and then you can do what you were trying to do with the bulletArray[index].hitTest and it should hopefully work. (Do the same thing where you store the actual movieclip for the other array also)

败给现实 2025-01-13 11:38:44

您正在从bulletArray中删除2次:

       bulletArray.splice(zz,1);
       bulletArray.splice(yy,1);

我猜最后一次应该是敌人的删除。当您稍后尝试删除已经从舞台上删除的敌人时,这可能会引发错误吗?

You are removing 2 times from bulletArray:

       bulletArray.splice(zz,1);
       bulletArray.splice(yy,1);

Last one should be enemy removal I guess. maybe this throws error when you later try to remove an enemy you already removed from the stage?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文