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.

AppGameKit Classic Chat / Getting Pixel Color From Sprite (Pixel perfect collision detection) - tier 1

Author
Message
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 29th Sep 2011 10:27 Edited at: 29th Sep 2011 10:55
I'm interested in developing an app with AppGameKit, and I'm wondering if/how I can get pixel-perfect collision detection from a sprite. Basically, back in VB6 days one could get a long-integer color ID from any given point within an image, and I am looking for similar functionality within AGK----even returning whether or not the portion of the sprite is transparent or solid would work.

I know pixel-perfect collision detection is CPU expensive, but I only need to do it once the user performs an action and not every frame either.

Thanks!

EDIT: An alternative would be storing the data in a 2-dimensional array, but the problem there would be reading the data into the array...... because unless AppGameKit does compression on text files (that would store the data), the files themselves would be huge.... or I would have to come up with my own compression scheme myself...

Hi there. My name is Dug. I have just met you, and I love you.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 3rd Oct 2011 03:42
I don't think there is a way to do this in AppGameKit, you have to rely on the createspriteshape command. I already posted with a similar question a while back.
I agree a simple, check for transparency would be nice for collision, it would make more complicated shapes work just as well as simple ones. I can see the need for the shape in physics based apps, but not for anything else.

LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 9th Oct 2011 04:23
We decided to avoid this type of command as it is performance intensive on some platforms, and your app would literally crawl on some devices when it left the safety of your development machine. There are alternatives to the challenges of creating a collision system for your game that does not use the pixel data of images to create your shapes, and they are often much faster than the per-pixel method of detection. Did you know you can slice your landscape into strips, and then grand each slide a 'shaped collision mode' using Box2D commands which wraps them in simply geometry. The result is very fast physics based landscape collision that will remain fast across all devices. If anyone is interested in these different collision ideas, post here and maybe we can collect some ideas for a new guide or video article

I drink tea, and in my spare time I write software.
Almus
12
Years of Service
User Offline
Joined: 27th Aug 2011
Location: Brasil
Posted: 28th Oct 2011 22:32
how i can make this "shaped collision mode"?, i am making a jump and run game, ive coded all the character moves like walk, run, jump, but now, i want to make a function to check its "feet" collision with my scenery, there is a mode to check the collision with all the scenery (its a tiled level) or i need to check every individual sprite collision? , i dont now how to use collisiongroup .
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 30th Oct 2011 02:10
A trick for advanced collision detection is to have separate colider sprites.
Make an invisible / transparent sprite and "track" your character with this new sprite, with the appropriate offset. You of course only need to check the "foot overlay" for collisions then.

Another performance booster is to use box collision for everything, then if this collision is true, process it further with per-pixel or other critical / specific testing.

For collision groups, set your background tiles in group 1, your platform tiles into group 2 , enemies into group 3 and so on. I think you can have 16 groups and when you test your "feet" you only test against group 2 in this case to see if he has collided with a platform sprite.

Cheers

Login to post a reply

Server time is: 2024-04-24 17:11:25
Your offset time is: 2024-04-24 17:11:25