Just wondering how I can get the position of a node that will be the current position if it is not moving, but if there is a CCMoveTo action being performed I need the position it is moving to.
Is this already built in or will I have to implement it myself, if so any suggestions on how I would go about it?
Thanks for the help,
Ben
Usually, if there are already built-in methods that “single-lined-ly” give you the information that you want, for example using
[[CCDirector sharedDirector] running Scene]to get the current scene, it is a bad idea to create an ivar to keep track of the information for later querying.But if using the built-in methods are hackish or long-winded, with no guarantee for accuracy, then it is better to create an ivar.
So, just create an ivar on that node that you update whenever the position is changed or a CCMoveTo action is assigned.
Note: I’m calling the
-(NSArray *)getActionsByTarget:(id)targetmethod as hackish because it is not guaranteed that you can find theCCMoveToaction in it. The action might be embedded deep in[CCSequence actions:[CCFadeIn ...], [CCSpawn actions:[CCCallBlock actionWithBlock: ^{ [self runAction:[CCSequence actions:[CCDelay ...], [CCMoveTo ...], nil]]; }], [CCMoveTo ...], nil], [CCMoveTo ...], nil]. Now how in the world you would implement the logic that can correctly find all the threeCCMoveToand deduce which of it will give the final position?