문제

I'm trying to follow a tutorial for making an iOS game in SpriteKit, but also simultaneously porting it to OS X. (When I'm making my own game, I intend to do exactly that, plus it helps the learning sink in a little bit more than just copying spoon fed code)

So far, everything has gone spritely (pun intended) and I've been able to troubleshoot or research every problem I've come across, but alas, it could only last so long. It's probably something stupid simple too, but it evades me.

I'm trying to pull in a string from a plist dictionary

self.position = CGPointFromString( [ characterData objectForKey:@"StartLocation"]);

StartLocation is the key for the coordinates, in the format of "{0,0}".

When building for iOS, it works beautifully. When building for OS X, it fails. I believe the issue lies with "CGPointFromString" being unique to the iOS development environment. It only appears in iOS documentation. The thing is, I can't find any OSX equivalents.

I realize that I could PROBABLY get it to work by breaking the coordinates into two float values with two separate dictionary entries for x and y, but I don't know if the writer of the tutorial did this intentionally and that would break something down the road, plus I want to know how to convert from one data type to another on OS X too.

Please help! /Thank you!

도움이 되었습니까?

해결책

On OSX you have NSPointFromString but not CGPointFromString. You also have NSPointToCGPoint and NSPointFromCGPoint if you want typecast them.

다른 팁

Not as direct but this works:

NSPoint cocoaPoint = NSPointFromString(theString);
CGPoint point = NSPointToCGPoint(cocoaPoint);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top