Learning Objective-C by Developing iPhone Games by Joseph D.Walters

Learning Objective-C by Developing iPhone Games by Joseph D.Walters

Author:Joseph D.Walters
Language: eng
Format: azw3
Published: 2014-04-22T08:14:46+00:00


[ 128 ]

//get our bomb image

UIImage *bombImage1 = [UIImage imageNamed:@"bullet.png"]; Let's find the start location for our bullet. In this case, we want to find out where the center of the player's ship is at the moment they hit the fire button and launch the bullet from there. This is done with the help of the following code:

//get the center x position of the player's ship

int bulletWidth = 8;

int bulletStartX = playerView.frame.origin.x +(

playerView.frame.size.width/2)-(bulletWidth/2);

Next, get the bullet image, cut it into two images, and add them to an array.

Create an image view in which the bullet to play inside. Set the image view's animationImages to the array as follows:

//make two images from the bomb image using these rects

CGImageRef imageRef = CGImageCreateWithImageInRect([bombImage1

CGImage], CGRectMake(0, 0, 32, 64));

CGImageRef imageRef2 = CGImageCreateWithImageInRect([bombImage1

CGImage], CGRectMake(33, 0, 32, 64));



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.