开发者

CCNode get position an action is moving it to

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)target method as hackish because it is not guaranteed that you can find the CCMoveTo action 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 three CCMoveTo and deduce which of it will give the final position?


You need to have any CCMoveTo action object, and then search it by CCNode object that you want to get the position of. If you found the CCMoveTo object that is targeted for the CCNode object, then you can get the position from the CCMoveTo object. For example, add -(NSArray *)getActionsByTarget:(id)target method or something like that to CCActionManager class.

Or, create derived class from CCNode to have the position of the CCMoveTo action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜