开发者

Very Basic cocos 2d questions

开发者 https://www.devze.com 2023-03-10 05:06 出处:网络
I\'m new to cocos2d so I am a b开发者_如何学Goit confused by some things: The term \"child\" keeps popping up. At

I'm new to cocos2d so I am a b开发者_如何学Goit confused by some things:

  1. The term "child" keeps popping up. At first I thought it was a subclass, now I perceive to be a sort of dynamic instance variable? Can anyone explain this a bit better?

  2. The class CCSpriteBatchNode is some kind of array of CCSprites which calls a method that renders the graphical part of its elements/children from a sprite sheet. Is my explanation somewhat correct?

  3. My book (learning cocos 2d a beginners guide) shows a design setup where the CCSpriteBatchNode has several objects as children. I'm a bit confused because I'm used to separating drawing classes from logical classes, AKA "Separation of concerns". Is this something cocos2d doesn't abide by and we shouldn't either?


  1. Parent-child is just a relationship between CCNode and their subclasses in cocos2d. For example if you want a moon turning around the moving planet it is really hard to calculate the absolute path of the moon. But you can make it the child of a planet, and in this case its position, rotation and so on, will be relative to the planet's coordinates. So parent-child relationship is just grouping.

  2. CCSpriteBatchNode is a parent to all its children, but the position of its children are relative to CCSpriteBatchNode parent. Such approach is used because BatchNode is rendering all its children at the same time. That is done to increase performance (no texture switching).

  3. Batch rendering is faster. If your logic is good, CCSpriteBatchNode does not make it worse. For example, you can have a character with a body, arms and legs and you want to render it using BatchNode. You just add the body as a child to BatchNode, then add arms and legs as children to the body. Logic is kept, performance is increased.

0

精彩评论

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