Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Sprite transparency and pixel-perfect collision. Oh boy...

Author
Message
Pi314159266
User Deleted
Posted: 29th Jul 2010 22:07
I recently decided to create a 2d side scroller without much thought about what kind of code I would need to write. As it turns out, very little programming can be done until 2d sprite collision is worked out, and being the perfectionist that I am, it is vital that the collision detection is pixel-perfect. I wrote the code for it, and it didn't work. I scratched my head for 2 days trying to figure out what the problem was but I couldn't find anything.

By the way, iPlayerX and iPlayerY are the coordinates of the player sprite, and it is always sprite1 for simplicity.



Turns out my sprites weren't entirely transparent. I don't know how I figured that out because I made the images in Photoshop with total transparency and saved them as PNGs, but whatever. I tried the collision again using images that I was sure had total transparency and it worked perfectly! I also changed the collision check to return true if the value of the alpha is greater than 30 to clear up any fuzzy edges.

However, I honestly have no idea how to make the collision work with my original sprite as it seems to have a sort of half-transparent border around it that doesn't even show up in Photoshop. This isn't really so much of a question I guess, but I did want to share my code with other developers having similar problems, and also ask for any insight you guys have on how I can possibly improve my code. Thanks for any help!
Pi314159266
User Deleted
Posted: 30th Jul 2010 05:30
Hold up, the collision detection worked with small images, but not when I resized the images. Very screwy business going on...
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 31st Jul 2010 15:14
Quote: "Turns out my sprites weren't entirely transparent. I don't know how I figured that out because I made the images in Photoshop with total transparency and saved them as PNGs, but whatever. I tried the collision again using images that I was sure had total transparency and it worked perfectly! I also changed the collision check to return true if the value of the alpha is greater than 30 to clear up any fuzzy edges.
"


Sounds like Photoshop is using Anti-Aliasing during its rendering stage. See if there is any way to turn it off. That should take care of the "fuzzy edges." As a side-note, however, the image would look a bit differently...

JTK

Login to post a reply

Server time is: 2024-11-19 20:28:20
Your offset time is: 2024-11-19 20:28:20