在 cocos2d 中将多个 CCSprite 组合成一个分组对象 [英] combining multiple CCSprites into one grouped object in cocos2d

查看:17
本文介绍了在 cocos2d 中将多个 CCSprite 组合成一个分组对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用 cocos2d 将多个 CCSprite 动态组合成一个分组对象的最佳方法是什么.

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

我必须从一组多个 CCSprite 中动态创建角色.元素在组合后不能相对移动 - 并且永远不会再次分离.

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.

当它们组合在一起时,它们在移动和转动等方面的行为应该像一个 CCSprite.

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

我在 cocos2d 中找不到任何东西,还是我必须使用物理引擎才能实现这一点?恐怕,使用 Box2d(没有经验)会产生大量额外的编码开销和工作量.

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.

非常感谢

推荐答案

创建一个空的 CCSprite 并添加来自不同 sprite 的 body 部分.示例:

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];

等等.这样您就可以旋转名为 body 的精灵,并且所有身体部位都会相应地调整.

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

这篇关于在 cocos2d 中将多个 CCSprite 组合成一个分组对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆