Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CGPoints in an NSArray

I have been trying to create an array stating the location of a UIImageView in an app I've been working on. What I am trying to do is by using an array I can store the location of my "player" image by using its x,y and z coordinates. The script I am trying to accomplish would look like

NSArray *location[3];
-(IBAction)startup;{
[location addObject: player.center.x];
[location addObject: player.center.y];
[location addObject: playerheight];
}

So I will be able to access this array to move my "player" on the screen in "3-dimensions", but I don't know how to convert the CGpoint values to NSValues so they can be used in the array, is there a simple way to do this inside of the array?

like image 371
Jason Avatar asked Dec 03 '22 05:12

Jason


1 Answers

To convert floating point values to objects, use NSNumber. NSValue has wrappers for geometric types like CGPoint. Either would work for you.

[NSValue valueWithCGPoint:player.center];

[NSNumber numberWithFloat:player.center.x];
[NSNumber numberWithFloat:player.center.y];
like image 75
drawnonward Avatar answered Jan 24 '23 04:01

drawnonward