How Do I Animate a sprite that is attached to a cpShape??
here's part of my code - it may not make complete sense because i think i'm mixing two different ways of doing things.
Obviously, I am a little lost here. I can't figure out how to "attach" my SpriteFrames to cpShape (if that is even possible).
Code: Select all
-(id) initWithChipPlayerImage
{
if ((self = [super init]))
{
CGSize screenSize = [[CCDirector sharedDirector] winSize];
smgr = [[SpaceManagerCocos2d alloc] init];
[smgr addWindowContainmentWithFriction:0.8 elasticity:0.2 inset:cpvzero];
[smgr addSegmentAtWorldAnchor:cpv(0,65) toWorldAnchor:cpv(480,65) mass:STATIC_MASS radius:1];
cpShape *playerSprite = [smgr addCircleAt:cpv(350,160) mass:8 radius:15];
[super initWithShape:playerSprite file:@"ship-anim0.png"];
self.autoFreeShape = YES;
self.spaceManager = smgr;
[self schedule:@selector(startGravity:) interval:3.0];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"game-art.plist"];
CCSpriteBatchNode *sheet1 = [CCSpriteBatchNode batchNodeWithFile:@"game-art.png" capacity:5];
[self addChild:sheet1];
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
CCSprite *sapusSprite1 = [[CCSprite alloc] initWithSpriteFrameName:@"ship-anim0.png"];
CCAnimation *sapusAnim = [[CCAnimation alloc] initWithName:@"select" delay:0.15f];
[sapusAnim addFrame:[cache spriteFrameByName:@"ship-anim1.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"ship-anim2.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"ship-anim3.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"ship-anim4.png"]];
//[sapusSprite1 addAnimation: sapusAnim];
sapusSprite1.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
[sheet1 addChild:sapusSprite1];
CCAnimate *animate = [CCAnimate actionWithAnimation: sapusAnim restoreOriginalFrame:NO];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];
[sapusSprite1 runAction:repeat];
}
return self;
}
Code: Select all
cpSpace *space;
cpShape *blockShape;
cpBody *blockBody = blockShape->body;
CCNode *parent = (CCNode*)data;
cpSpaceAddShape(space, blockShape);
cpSpaceAddBody(space, blockBody);
Anyone have any links to tutorials or sample code that addresses this. Thanks very much!!!!!