Combining CCSprite with PhysicsSprite question

Official forum for the Chipmunk2D Physics Library.
Post Reply
Arietis
Posts: 2
Joined: Thu Jul 05, 2012 12:23 pm
Contact:

Combining CCSprite with PhysicsSprite question

Post by Arietis »

Hello!
I'm trying to add child CCSprite to the PhysicsSprite with specific cpBody. But when i run simulation, child doesn't moves together with parent and just stand still. Any idea what i'm doing wrong? :) Here the code:

Code: Select all

PhysicsSprite *parent = [PhysicsSprite spriteWithSpriteFrameName:@"bg01_parent.png"];
float parentWidth = parent.contentSize.width;
float parentHeight = parent.contentSize.height;
float parentMass = 500.0;
cpBody *parentBody = cpBodyNew(parentMass, cpMomentForBox(parentMass, parentWidth, parentHeight));
parentBody->p = [self convertPoint:ccp(420, 104)];
 cpSpaceAddBody(space, parentBody);
cpShape *shape = cpBoxShapeNew(parentBody, parentWidth, parentHeight);
shape->e = 0.5;
shape->u = 1.0;
cpSpaceAddShape(space, shape);
[parent setPhysicsBody:parentBody];
[batch addChild:parent z:0 tag:kparent];
CCSprite *childBack = [CCSprite spriteWithSpriteFrameName:@"bg01_child_back.png"];
[parent addChild:childBack z:0 tag:0];
CCSprite *childFront = [CCSprite spriteWithSpriteFrameName:@"bg01_child_front.png"];
[parent addChild:childFront z:1 tag:0];
Thanks.

Update: i have found that sprites start following parent if i'm adding any kind of animation action to it. So the question is probably not chipmunk related in this case. :)
Zue
Posts: 3
Joined: Fri Jan 13, 2012 5:07 am
Contact:

Re: Combining CCSprite with PhysicsSprite question

Post by Zue »

[little offtop]
I think you're wrong to use a batch.
If I remember correctly, in the Cocos2D, to accelerate the rendering of a large number of sprites, they must have the same texture (one texture file). What you have written, does not increase the efficiency of rendering. (If your course is variable batch CCBatchNode)
Arietis
Posts: 2
Joined: Thu Jul 05, 2012 12:23 pm
Contact:

Re: Combining CCSprite with PhysicsSprite question

Post by Arietis »

Sprite textures are parts of texture atlas so i suppose it's ok to use batch like that. But the different question would be "will batch node count child sprites of physics sprite when rendering or no".
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Combining CCSprite with PhysicsSprite question

Post by slembcke »

I know there are some peculiarities involved with children of batched sprites, but I don't really remember what off the top of my head. You'll probably get a better answer on the Cocos2D forums.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests