Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-17-2010, 07:46 AM   #1 (permalink)
Banned
 
Join Date: Dec 2009
Posts: 61
iPhoneDevelopment is on a distinguished road
Default Pixel alpha collision detection

The only form of collision detection that I have used is to do with shapes, rather than the alpha value of pixels. Does anyone know an easy way to implement pixel collision detection?

Thanks

Cam
iPhoneDevelopment is offline   Reply With Quote
Old 02-17-2010, 08:02 AM   #2 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Moving pixels? How are you gonna define these, they have to be UIImages or drawn with CGContextAddArc.

Then you use CGRectIntersectsRect and call it from an NSTimer.
ZunePod is offline   Reply With Quote
Old 02-17-2010, 08:26 AM   #3 (permalink)
Banned
 
Join Date: Dec 2009
Posts: 61
iPhoneDevelopment is on a distinguished road
Default

CGRectIntersectsRect is good for rectangles, but I need to do far more complex shapes, thus why pixel detection and not just geometry based. Thanks for your reply

Cam
iPhoneDevelopment is offline   Reply With Quote
Old 02-17-2010, 08:54 AM   #4 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
ZunePod is on a distinguished road
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

Quote:
Originally Posted by iPhoneDevelopment View Post
CGRectIntersectsRect is good for rectangles, but I need to do far more complex shapes, thus why pixel detection and not just geometry based. Thanks for your reply

Cam
Oh I getcha.

Lemme see...

http://www.iphonedevsdk.com/forum/ip...-response.html
ZunePod is offline   Reply With Quote
Old 02-17-2010, 09:23 AM   #5 (permalink)
Registered Member
 
Centurion Games's Avatar
 
Join Date: Nov 2009
Location: Beaverton, OR
Posts: 119
Centurion Games is on a distinguished road
Default

Quote:
Originally Posted by iPhoneDevelopment View Post
CGRectIntersectsRect is good for rectangles, but I need to do far more complex shapes, thus why pixel detection and not just geometry based. Thanks for your reply

Cam
Your most likely better off doing some combination of multiple bounding circles/boxes instead of pixel perfect. Specially if you do any programmatic rotations or scaling.
__________________
Centurion Games|@centuriongames
Centurion Games is offline   Reply With Quote
Old 02-18-2010, 03:41 AM   #6 (permalink)
Maker of Games
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 395
Mr Jack is on a distinguished road
Default

Quote:
Originally Posted by iPhoneDevelopment View Post
The only form of collision detection that I have used is to do with shapes, rather than the alpha value of pixels. Does anyone know an easy way to implement pixel collision detection?
You could store a bitmask generated from your images at load time, choosing an arbitary alpha value to define as colliding. Then it's a simple matter of offsetting the two bit masks and looking to see if both have the pixel set.

Make sure you perform a cheaper form of intersection test first - i.e. a circular or bounding box test - because pixel/pixel comparisons are going to be slow.

And, to be honest, they're probably unneeded. What exactly are you trying to do collision on.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Old 02-18-2010, 05:25 AM   #7 (permalink)
Banned
 
Join Date: Dec 2009
Posts: 61
iPhoneDevelopment is on a distinguished road
Default

I have attached a basic example of the kind of shapes that I will be colliding, and from it you can probably see why I need pixel detection. I doubt I would need to create a mask, as the image already contains the transparent pixels. My question: can anyone give me a basic way of detecting if the pixels in my image are transparent or not?

Thanks,

Cam
Attached Images
File Type: jpg 1.jpg (27.7 KB, 0 views)
iPhoneDevelopment is offline   Reply With Quote
Old 02-18-2010, 06:46 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 192
Abel is on a distinguished road
Default

Quote:
Originally Posted by iPhoneDevelopment View Post
I have attached a basic example of the kind of shapes that I will be colliding, and from it you can probably see why I need pixel detection. I doubt I would need to create a mask, as the image already contains the transparent pixels. My question: can anyone give me a basic way of detecting if the pixels in my image are transparent or not?

Thanks,

Cam
Not sure this is the easiest way, but I would get an array with all the bitmap data then parse the alpha values to determine which pixel is transparent or not
__________________
GoFax - Mobile faxing
Tipper
ShareIt
Abel is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 398
8 members and 390 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0