开发者

Should I be subclassing the CCSprite to schedule updates in cocos2d?

The documentation says things like:

Each node, by default, has no updates. If you want to update the state of your node you should schedule a callback

The recommended way to do it is by calling CCNode scheduling methods, and not by using NSTimer. CCNode has the following method to timer

scheduleUpdate scheduleUpdateWithPriority:(int)priority scheduleSelector:(SEL)selector scheduleSelector:(SEL)selector interval:(float)interval Properties of these method:

The scheduled callbacks will be called only if the node is “on stage”, if the node is part of a living scene The scheduled callbacks won't be called if the Director is paused You should not DRAW anything in these methods They will receive the delta time as an argument

Note: I am reading 'update' as, change the state of the Sprite according to what needs to be happening next in the game for this frame.

Does this mean I am suppose to be subclassing the CCSprite and then 开发者_StackOverflow中文版giving it new implementation for the update method?

(If so, would I need to call the original overridden method explicitly?)

Source: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:draw_update


I assume you are talking about the game logic, and how it should update the sprite.

If that is the case, you should go with composition. Create a CCNode subclass, which has a CCSprite as an instance variable (Composition).

For more on this, read: http://www.learn-cocos2d.com/2010/06/prefer-composition-inheritance/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜