Sign in to follow this  

Confused on Pixel perfect detection (Riemers tutorial)

Recommended Posts

I was using Riemers tutorials and have been now trying to implement my own pixel perfect detection, but I have run into a problem in the rotation. If I rotate my image X amount of pixels the pixel perfect detection then fails, and I am not sure as to why.
//What the zombies get initialized to.
ZombieList.Add(new Sprite("Game/Zombie"));
                ZombieList[ZombieList.Count - 1].Position.Y = ZombieList[ZombieList.Count - 1].Height;
                ZombieList[ZombieList.Count - 1].Position.X = rnd.Next(0, 800);
                ZombieList[ZombieList.Count - 1].Origin.Y = ZombieList[ZombieList.Count - 1].Height;
                ZombieList[ZombieList.Count - 1].Velocity.Y = (rnd.Next(1, 10) / 100f);
                ZombieList[ZombieList.Count - 1].Rotation = 30;
                ZombieList[ZombieList.Count - 1].Scale = new Vector2(.5f);
                ZombieList[ZombieList.Count - 1].FadeInOut = true;

//I get a point then I use the inverse matrix of the image and 
//then find out where it hits in the texture
//If the .a >0 that means its not transparent and thus there is a hit.
public bool TexturesCollide(float mouseX, float mouseY)
            bool returnValue = false;

            Matrix thisSprite = 
                Matrix.CreateScale(this.Scale.X, this.Scale.Y, 1) *
            Matrix invertSprite = Matrix.Invert(thisSprite);

            Vector2 pos1 = new Vector2(mouseX, mouseY);
            Vector2 pos2 = Vector2.Transform(pos1, invertSprite);

                    if (spriteColorArray[(int)pos2.X, (int)pos2.Y].A > 0)
                        returnValue = true;                        //This returns when the point is non transparent

            return returnValue;

Any help would be appreciated! thanks.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this