I'm looking over some sample code in a cocos2d project. I had previous built a project using Core Graphics (Quartz) where coordinate (0,0) is the upper left corner of the screen. In this project, if I use CGPointMake(0,0) it is in the lower left corner. I understand that the coordinate systems are different, but where exactly would a program specify which coordinate system to use? What is the setting or method that actually makes this switch?
1 Answers
There is no switch. If you want to work with Cocos2D, get used to its coordinate system origin being at the lower left corner of the screen.
I've seen users make all kinds of attempts to "fix" this, either by hacking around in the Cocos2D source code, or by overriding the setPosition property of all nodes only to find out that this isn't enough. I bet all of them have been running into lots of issues, including the fact that whenever you need to re-use someone else's code, you're faced with making the necessary coordinate system fixes to that code as well. It's a never-ending struggle that is really not worth spending any amount of time in.
Instead, rather than changing the code, change your perception. Get used to a different coordinate system and thinking in it. Way easier and much less trouble for the future. After all, all you really need to change in your head is that the sign of the Y coordinate has changed.

- 64,284
- 20
- 132
- 217
-
thanks, i don't mind using it the way it is, I'm just wondering why it is working the way it is. I can understand why setPosition, which is in the cocos framework itself, can work any way the cocos developers designed, and that's fine, but why does CGPointMake, a native iOS function, also position with the new coordinate system? somewhere in the program there must be a setting that is telling the compiler or runtime to use a different coordinate system. – johnbakers Nov 17 '11 at 15:25
-
This is because of OpenGL and the way it is setup. There is a way to change the coordinate system but the current setup is simply deeply interwoven with how Cocos2D works: http://stackoverflow.com/questions/611468/in-opengl-es-how-do-i-convert-screen-coordinates-to-world-coordinates – CodeSmile Nov 17 '11 at 22:10
-
thanks. i don't have any desire to change the coordinate system but i was just curious how native calls in the iPhone SDK could end up using different coordinates, how this was manipulated in the program. i'll assume it is fairly complicated. – johnbakers Nov 18 '11 at 02:04