dudemanthing
August 7th, 2010, 05:32 PM
Hey everyone!
While designing a bullet hell shooter (http://en.wikipedia.org/wiki/Bullet_hell#Bullet_hell), I thought of an important way of optimizing the collision detections between the player and the hundreds or thousands of on-screen bullets.
The detection method I am using is the popular pixel perfect detection method by Troy Gilbert:
http://troygilbert.com/2009/08/pixel-perfect-collision-detection-revisited/
Instead of pushing the thousands of bullets in an array, looping through it, and checking for a hit for each one, we can just make one container DisplayObjectContainer (for example, a MovieClip or a Sprite) and spawn each bullet inside that container with addChild.
Then all we have to do is check if the player's hitbox touches the container, which will let us know if it's come into contact with a bullet, and if so kill the player and clear the screen of bullets.
However, this doesn't work the other way, for player's bullets on enemies, because of enemy HP and needing to know hits on specific enemies. Luckily the number of bullets from the player tends to be much smaller than the number of enemy bullets.
While designing a bullet hell shooter (http://en.wikipedia.org/wiki/Bullet_hell#Bullet_hell), I thought of an important way of optimizing the collision detections between the player and the hundreds or thousands of on-screen bullets.
The detection method I am using is the popular pixel perfect detection method by Troy Gilbert:
http://troygilbert.com/2009/08/pixel-perfect-collision-detection-revisited/
Instead of pushing the thousands of bullets in an array, looping through it, and checking for a hit for each one, we can just make one container DisplayObjectContainer (for example, a MovieClip or a Sprite) and spawn each bullet inside that container with addChild.
Then all we have to do is check if the player's hitbox touches the container, which will let us know if it's come into contact with a bullet, and if so kill the player and clear the screen of bullets.
However, this doesn't work the other way, for player's bullets on enemies, because of enemy HP and needing to know hits on specific enemies. Luckily the number of bullets from the player tends to be much smaller than the number of enemy bullets.