Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whats the different among Cocos2d's touch locationInView, covertToGL, and convertToNodeSpace?

I'm a beginner and confused with them. In console, their location have different values. So, what is the meaning of their own?

like image 624
zack Avatar asked Jan 20 '23 02:01

zack


1 Answers

locationInView will give you the current location of the touch by the user according to normal cartesian co-ordinate system which is in portrait mode.

However, you need to convert those co-ordinates into OpenGL co-ordinates for getting the actual location. convertToGL just converts the co-ordinates into the current layout which maybe landscape mode or any other mode.

While, convertToNodeSpace will be used in, for example, tile-based games, where you have a big map. convertToNodeSpace will convert your openGL touch co-ordinates to the co-ordinates of the .tmx map or anything similar.

For example, consider following figure. you maybe having a map of (1000,2000) size.

Now, when you touch the screen for the first time co-ordinates will be stored in normal portrait mode, which after converting into openGL will give you the correct co-ordinates on screen, say (100,100). But your current location on map is (800,800). To get this location, u need convertToNodeSpace.

Hope this helps. :)

like image 67
mayuur Avatar answered Mar 01 '23 22:03

mayuur