Is it possible to do pixel perfect collision in a view based application ? I've been looking for example codes but with no luck... Also can you use colored bitmaps to represent collision for a certain color ?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
You can. It looks like it's easiest if you use a CGImage though.
You could create a 2D boolean array to read the pixel values to construct a hit grid (basically a 2x2 matrix) and then store that with your game object class.
You would need direct access to the pixel data for the CGImage (the code is here) then use a for loop, reading the pixel data into the array boolean values:
The method pixelIsOpaque() above, obviously doesn't exist, just replace with whatever the sample code gives you to extract the pixel value. You are storing whether a pixel exists (basically check if the pixel is opacity > 0)
Once you have this grid (generate it at the beginning of your program once and store the resultant 2D array inside the game object) then you need a collision detection method.
I just wrote this code on the fly so i may not be 100% compilable but i hope it gives you the idea. You could easily modify this but instead of comparing against opacity, simply compare against pixel colour value again, see here for getting the raw colour data.