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:
The enemy class: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);
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!!!Code:public Rectangle GetBounding() { return new Rectangle((int)this.vPosition.X, (int)this.vPosition.Y, (int)vTileSize.X, (int)vTileSize.Y); }


Reply With Quote

Mark Thread Resolved