combining multiple CCSprites into one grouped object in cocos2d

别说谁变了你拦得住时间么 提交于 2019-12-18 04:55:23

问题


I wonder what's the best approach to combine several CCSprites dynamically into one grouped object using cocos2d.

I have to dynamically create characters from a set of multiple CCSprites. The elements can't move relative to each other after combined - and are never separated again.

When combined they should behave just like one CCSprite in terms of moving and turning etc.

I couldn't find anything in cocos2d, or do I have to use a physics engine just to achieve this? I am afraid, using Box2d (without experience) creates a lot of additional coding overhead and effort.

Many thanks


回答1:


Create an empty CCSprite and add the body parts from different sprites. Example:

CCSprite *body = [CCSprite node];
CCSprite *arm = [CCSprite spriteWithSpriteFrameName:@"arm.png"];
[arm setPosition:CGPointMake(10,10)];

[body addChild:arm];

And so on. This way you can rotate the sprite named body and all body parts will adjust accordingly.



来源:https://stackoverflow.com/questions/4554639/combining-multiple-ccsprites-into-one-grouped-object-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!