针对所有子类 CCSprite (cocos2d)

发布于 2024-10-09 08:41:54 字数 229 浏览 0 评论 0原文

我正在研究一种结束关卡的方法,但要做到这一点,我必须看到所有敌人角色都已被杀死。 如果我的敌人是CCSprites,我该如何制作一个方法来检测它们是否全部死亡?我正在使用一个名为“enemyHp”的整数来跟踪他们的健康状况。例如,这是我用来删除敌人的 if 语句 if (enemy.enemyHp <= 0) {

回顾一下 - 我想创建一个方法来检测所有敌人何时被杀死。

谢谢

I'm working on a method to end the level, but to do so, I have to see that all of the enemy character have been killed.
If my enemies are CCSprites, how do I make a method that detects if all of them are dead? I'm tracking their health with an int called enemyHp. For example, this is an if statement I made to remove the enemy if (enemy.enemyHp <= 0) {

To recap - I want to make a method that detects when all enemies have been killed.

Thanks

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

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

发布评论

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

评论(1

习惯成性 2024-10-16 08:41:54

您必须将这些精灵添加到数组(NSArray)中,然后循环该数组。

for(Enemy * enemy in enemies)
{
  if (enemy.enemyHp <= 0) {    
    //kill it
  }  
}

You would have to add those sprites to an array (NSArray) and then loop through that array.

for(Enemy * enemy in enemies)
{
  if (enemy.enemyHp <= 0) {    
    //kill it
  }  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文