Results 1 to 3 of 3

Thread: [XNA 4] Pixel Collision problems with animation

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Question [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!!!
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [XNA 4] Pixel Collision problems with animation

    Which array are you using for animation that you are getting the error at?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    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.
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width