CreateJS - 碰撞检测与多个对象在两个容器中
问题描述:
这是我使用我的碰撞检测代码:CreateJS - 碰撞检测与多个对象在两个容器中
for(var k = 0; k < enemies.children.length; k++) {
if(bullet.x >= enemies.children[k].x + wingmanWidth ||
bullet.x + sizeBullet <= enemies.children[k].x - wingmanWidth ||
bullet.y >= enemies.children[k].y + wingmanHeight ||
bullet.y + sizeBullet <= enemies.children[k].y)
{
//not
}else {
// collsion detected
}
在敌人容器一颗子弹对象和多个僚机对象之间检测到碰撞。现在我想要检测子弹容器中的多个子弹与敌人容器中的多个僚机对象之间的碰撞。
答
通过添加另一个for循环固定它作为约瑟夫建议
for(var k = 0; k < enemies.children.length; k++) {
for(var j = 0; j < bulletsContainer.children.length; j++) {
if(bulletsContainer.children[j].x >= enemies.children[k].x + wingmanWidth ||
bulletsContainer.children[j].x + sizeBullet <= enemies.children[k].x - wingmanWidth ||
bulletsContainer.children[j].y >= enemies.children[k].y + wingmanHeight ||
bulletsContainer.children[j].y + sizeBullet <= enemies.children[k].y) {
//not
} else {
//yes
}
}
问题是什么?只需为每个子弹添加一个“for”循环。 –