Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-01-2010, 04:29 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 43
Nabopolassar is on a distinguished road
Default CGPoint from a string

O.K.
I have many CGPoints, all in viewDidLoad like this:
Code:
bRookStart = CGPointMake(372, 93);
		bQueenStart = CGPointMake(372, 57);
And I want to be able to use these easily without a lot of if statements... So I looked online and tried lots of things, but nothing worked. The following is probably the closest I got, but my new piece turned up at 0,0 (this is incomplete code, only the important part. The rest all works fine).
The pieceToAdd is a string such as bRook or bQueen.
Code:
CGPoint newPoint = CGPointFromString([NSString stringWithFormat:@"%@Start", pieceToAdd]);

myNewPiece.center = newPoint;
any help would be greatly appreciated.
Nabopolassar is offline   Reply With Quote
Old 08-01-2010, 04:33 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Switzerland
Age: 26
Posts: 35
Shod is on a distinguished road
Default

from the documentation:

CGPointFromString
Returns a Core Graphics point structure corresponding to the data in a given string.

CGPoint CGPointFromString (
NSString *string
);
Parameters
string
A string object whose contents are of the form “{x,y}”, where x is the x coordinate and y is the y coordinate. The x and y values can represent integer or float values. An example of a valid string is @”{3.0,2.5}”. The string is not localized, so items are always separated with a comma.
Return Value
A Core Graphics structure that represents a point. If the string is not well-formed, the function returns CGPointZero.

Discussion
In general, you should use this function only to convert strings that were previously created using the NSStringFromCGPoint function.
Shod is offline   Reply With Quote
Old 08-01-2010, 04:35 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 43
Nabopolassar is on a distinguished road
Default

Yes, I assumed that was something like that, I only put that up to show I had made some effort. But can you help me? It's probably very simple.
Nabopolassar is offline   Reply With Quote
Old 08-01-2010, 04:36 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 43
Nabopolassar is on a distinguished road
Default

Or should I just store my points as strings? That may be easiest...
Nabopolassar is offline   Reply With Quote
Old 08-01-2010, 04:44 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

If I understand what you are trying to do, then you could use a static array of CGPoints. Strings are a messy and inefficient way to store points.

And if all these points are the centers of squares on a chessboard, then the neatest way of all would be to create a function that returned the CGPoint for a given row and column.
RLScott is offline   Reply With Quote
Old 08-01-2010, 04:53 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 43
Nabopolassar is on a distinguished road
Default

So I would populate "arrayOfStartPoints" with my CGPoints, and then replace pieceToAdd with an integer, and do something along the lines of [arrayOfStartPoints objectAtIndexieceToAdd]?
Thank you, I'll try that.

As for the row/column function, my app isn't exactly a chess game; I just need to have 12 start points from where the player drags the pieces.
Nabopolassar is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 322
9 members and 313 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, Objective Zero, rayjeong, revg, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:18 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0