开发者

Growing circles in cocos2d and chipmunk

I'm trying to create a growing circle in chipmunk, that starts growing when you touch and hold your finger at a location. I haven't found any specific help function for that in chipmunk, wondering if anyone has any advice, tip or tricks for how to do that.

One way would be to create a circle a little bigger than the previous one and destroy the old one each update circle. Maybe there is a easier way, anyone has any thoughts?

Thanks

UPDATE: At the moment I using the following method:

In my actionLayer class:

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [touch locationInView: [touch view]];
    CGPoint circleOrigin = [[CCDirector sharedDirector] convertToGL: touchLocation];

    spriteObject = [[[CPHatchimal alloc] initWithSpace:space atLocation:circleOrigin] autorelease];
    [sceneSpriteBatchNode addChild:spriteObject z:2];

    return YES;
}

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    [spriteObject setGrowCircle:NO];
}

In my "spriteObject" class:

-(void) update:(ccTime)deltaTime {
    if (growCircle) {
        CGPoint location = ccp(circleOrigin.x, circleOrigin.y);
        cpFloat r = ((cpCircleShape*) shape)->r;
        r++;

        NSString *spritName = [self getCurrentSpriteName];
        [self setDisplayFrame:[[CCSpriteFrameCache sharedSpriteF开发者_运维百科rameCache] 
                           spriteFrameByName:spritName]];

        [self setScale:(0.01 * r)];

        cpSpaceRemoveStaticShape(space, shape);
        cpShapeFree(shape);


        body = cpBodyNewStatic();
        body->p = location;

        shape = cpCircleShapeNew(body, radius, cpvzero);
        shape->e = e;
        shape->u = u;
        shape->collision_type = collisionType;
        shape->data = self;

        cpSpaceAddStaticShape(space, shape);   

    }
}

At the moment I have pretty good fps (about 60), so I guess this solution is ok..


https://github.com/slembcke/Chipmunk-Physics/blob/master/include/chipmunk/chipmunk_unsafe.h

You have to import this header separately as I don't normally encourage people to use it. Make sure you understand that Chipmunk has no way to understand how the surface is moving or changing and the collisions will be mushy because of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜