[XNA 4] Pixel Collision problems with animation
Hello. I am using this sample of code from http://create.msdn.com/en-US/educati...on_2d_perpixel . In it it shows how to detect using pixel collision. However, I am having a bit of trouble when using animation, as it gives me an out of array exception. My sprite animations are on one sheet, as well as in 1 texture variable (for each type of enemy). The code i have is:
Code:
List<Enemy> lEnemy = egEnemy.GetEnemyList();
Color[] bulletTextureData;
Color[] enemyTextureData;
for (int i = 0; i < lBullet.Count; i++)
{
for (int x = 0; x < lEnemy.Count; x++)
{
bulletTextureData = new Color[((int)(lBullet[i].iTile - 1 )* (int)lBullet[i].vTileSize.X) * (int)lBullet[i].vTileSize.Y];
enemyTextureData = new Color[((int)(lEnemy[x].iTile - 1) * (int)lEnemy[x].vTileSize.X) * (int)lEnemy[x].vTileSize.Y];
if (lBullet[i].sType == "Player")
{
if (PublicVars.IntersectPixels(lBullet[i].GetBounding(),bulletTextureData,lEnemy[x].GetBounding(),enemyTextureData))
{
eeExplode.GenerateNewExplosion(lEnemy[x].vPosition,"Enemy");
lBullet.RemoveAt(i);
lEnemy.RemoveAt(x);
i--;
x--;
}
}
}
}
egEnemy.SetList(lEnemy);
The enemy class:
Code:
public Rectangle GetBounding()
{
return new Rectangle((int)this.vPosition.X, (int)this.vPosition.Y, (int)vTileSize.X, (int)vTileSize.Y);
}
That's the basis of the code...I'm not sure if I missed anything, so please ask for more code if you need it. Thanks!!!
Re: [XNA 4] Pixel Collision problems with animation
Which array are you using for animation that you are getting the error at?
Re: [XNA 4] Pixel Collision problems with animation
It highlights
Code:
enemyTextureData = new Color[((int)(lEnemy[x].iTile - 1) * (int)lEnemy[x].vTileSize.X) * (int)lEnemy[x].vTileSize.Y];
And gives an out of bounds exception... I may also do it for the bullet one as well.