If I have a sprite in a NSMutableArray of sprites in Cocos2d and need to access the x and y values of a specific sprite how can I do that?
[array objectAtIndex:0].position.y // or .x for x value
doesn’t work when trying to access the element of y from a specific sprite in the array. But, I can not think of any other way to get either the x or y value of a CCSprite. How can I get the x and y values of NSMutableArray containing CCSprites?
(And I can’t find any getX or getY methods either in the doc…)
You need to cast the value returned by
-[NSArray objectAtIndex:]so the compiler knows it’s aCCSprite *object:Alternatively, you could store the return value in a
CCSprite *variable:and then use this variable to obtain the corresponding position: