iDevGames Forums
Quick question on using arrays with CGFloats - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Quick question on using arrays with CGFloats (/thread-1983.html)



Quick question on using arrays with CGFloats - duncster - Dec 28, 2008 02:07 PM

Hi all,

I'm very new to Obj-C / Cocoa, and need a little guidance on the usage of arrays, if anyone would be so kind...

I am basically trying to create a bunch of CGPoint objects from coordinate values stored within a couple of arrays (each storing separate x and y values). I understand that the CGPointMake() function requires CGFloats, but I can't seem to work out how to get them in and out of the array!

How should I be doing this??

Any help would be gratefully appreciated!!

Cheers!

D.


Quick question on using arrays with CGFloats - SethWillits - Dec 28, 2008 08:44 PM

Errr... what?

I really don't understand what you're asking so I'll just throw out some possibilities to the only way I can interpret your question...


CGFloat floatArray[] = {...};
CGFloat aFloat = floatArray[someIndex];

--

NSArray * someArrayOfNSNumbersContainingFloats = ...;
CGFloat aFloat = [[someArrayOfNSNumbersContainingFloats objectAtIndex:index] floatValue];


Quick question on using arrays with CGFloats - AnotherJake - Dec 28, 2008 09:01 PM

[I'm guessing] He's probably looking for NSValue:

Code:
[myArray addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];



Quick question on using arrays with CGFloats - duncster - Dec 30, 2008 05:58 AM

Thanks for this!! Sorry about my garbled question. It was brought about mainly by my apparent lack of understanding of C arrays. I was thinking I had to work with NSArrays. Didn't realise that creating C arrays was so simple. I have since edumacated myself!!

Thanks again!

D.


Quick question on using arrays with CGFloats - duncster - Dec 30, 2008 06:05 AM

AJ - I opted for using NSNumber, which is, I think, a subclass of NSValue, but was told that I was doing things too inefficiently. I am now trying to do it another way (probably just using normal C arrays).

Basically, I'm simply trying to provide a UIImageView object (a sprite, of sorts...) with a list of x and y coordinates from which to use as the center positions for a bunch of new sub-UIImageViews (ie, sub-views of the "sprite" object).

Thanks for your help!

Dunc.


Quick question on using arrays with CGFloats - AnotherJake - Dec 30, 2008 09:59 AM

Yep, nothing wrong with good 'ol C arrays.