//1) Load the image:
UIImage *collisionImage = [UIImage imageNamed:@"levelmask.png"];
//2) Get the image size:
int width = (int)collisionImage.size.width;
int height = (int)collisionImage.size.height;
//3) Allocate our array for quick lookups and clear it:
unsigned char *collisionMap = (unsigned char *)malloc( width *
height );
memset( collisionMap, 0, width * height );
//4) Get access to the raw bits of the image
CFDataRef imageData = CGDataProviderCopyData( CGImageGetDataProvider
( collisionImage.CGImage ) );
const UInt32 *pixels = (const UInt32*)CFDataGetBytePtr( imageData );
//5) Build our collision map:
for( j = 0; j < (width * height); j++ )
if ( pixels[j] & 0xff000000 ) collisionMap[j] |= 1;
//6) Release what we no longer need:
CFRelease( imageData );
//Now, whenever you need to see if you hit something, you call a routine
//that does:
-(int)collisionForPoint:(CGPoint)point
{
int x = (int)point.x;
int y = (int)point.y;
// TODO: check for boundaries here
return collisionMap[(y*width)+x];
}
// instantiate a music player
MPMusicPlayerController *iPodMediaPlayer;
iPodMediaPlayer = [MPMusicPlayerController iPodMusicPlayer];
// Check if it is now playing
if([iPodMediaPlayer nowPlayingItem]){
NSLog(@"iPod is playing");
// Get the now playing item
MPMediaItem *nowPlayingMediaItem = [iPodMediaPlayer nowPlayingItem];
// Get info of the item
NSString *itemTitle = [nowPlayingMediaItem valueForProperty: MPMediaItemPropertyTitle];
NSString *itemArtist = [nowPlayingMediaItem valueForProperty: MPMediaItemPropertyArtist];
NSLog([[NSString alloc] initWithFormat:@"playing: %@ by %@", itemTitle, itemArtist]);
} else {
NSLog(@"iPod is not plaing");
}