I created a CCSprite and added to a cpShape and added to a cpSpace the shape and his body.
After that I run an animation the CCSprite with cocos2d, but nothing happens. If I don't add the sprite to the cpSpace the animation runs OK.
I don't know why :'( Can I animate ccsprites "related" with a cpSpace?
Here are some code:
mySprite = [CCSprite spriteWithFile:@"image.png"];
cpVect objPosition = -size.width/2, kobjY); // Set out of Screen
mySprite.position = objPosition;
[self addChild:mySprite z:3 tag:kObjTag];
int num = 23;
CGPoint objVerts[] = {
cpv(6.0f, -108.5f),
cpv(-3.0f, -106.5f),
cpv(-46.0f, -91.5f),
cpv(-50.0f, -89.5f),
cpv(-60.0f, -82.5f),
cpv(-66.0f, -74.5f),
cpv(-87.0f, -28.5f),
cpv(-87.0f, -24.5f),
cpv(-73.0f, 31.5f),
cpv(-72.0f, 33.5f),
cpv(-60.0f, 50.5f),
cpv(6.0f, 100.5f),
cpv(15.0f, 104.5f),
cpv(29.0f, 107.5f),
cpv(32.0f, 107.5f),
cpv(41.0f, 105.5f),
cpv(44.0f, 104.5f),
cpv(52.0f, 100.5f),
cpv(60.0f, 92.5f),
cpv(85.0f, 60.5f),
cpv(86.0f, -66.5f),
cpv(84.0f, -68.5f),
cpv(13.0f, -108.5f)
};
cpBody *objBody = cpBodyNew(0.0001f, INFINITY);
objBody->p = objPosition;
cpSpaceAddBody(mySpace, objBody);
objShape = cpPolyShapeNew(objBodyobjBody, num, objVerts, CGPointZero);
objShape->e = 0.5f; objShape->u = 0.5f;
objShape->data = mySprite;
cpSpaceAddShape(mySpace, objShape);
id objMove = [CCMoveTo actionWithDuration:2.0f position:ccp(kobjX,kobjY)];
id objMoveEaseIn = [CCEaseIn actionWithAction:[[objMove copy] autorelease] rate:2.0f];
[spriteObj runAction:objMoveEaseIn];