0

我有一个 cpCCSprite 的子类,它仅用于使用花栗鼠 spaceManager,我的类如下所示:

@implementation Helmet

+(id) helmetWithGame:(Game*)game {

    return [[[self alloc] helmetInit:game] autorelease];

}

- (id) helmetInit:(Game*)game {

    cpShape *helmet_1;
    cpShape *helmet_2;
    cpShape *helmet_3;
    cpShape *reference;

    reference = [game.spaceManager addCircleAt:cpvzero mass:STATIC_MASS radius:2];

    helmet_1 = [game.spaceManager addCircleToBody:reference->body radius:20 offset:cpv(-5, 2)];

    helmet_2 = [game.spaceManager addCircleToBody:reference->body radius:8 offset:cpv(16, -14)];

    helmet_3 = [game.spaceManager addCircleToBody:reference->body radius:8 offset:cpv(8, -14)];

    reference->group    =1;
    helmet_1->group     =1;
    helmet_2->group     =1;
    helmet_3->group     =1;

    [self initWithFile:@"Helmet.png"];
    [self setBody:reference->body];

    self.spaceManager = game.spaceManager;
    self.autoFreeShapeAndBody = YES;

    gameScreenSize = game.contentSize;

    return self;
}

- (void) generateAndShowOn:(Game *)game {

    float startX = (float)((arc4random_uniform(101)) + 100);//returns number from 100 to 200 and casts it as a float
    float startY;

    int endXRange = (game.contentSize.width * .8) - (game.contentSize.width * .5);
    float endX = (float)((arc4random_uniform(endXRange)) + (game.contentSize.width * .5));
    float endY;

    BOOL shouldStartTop;

    if ((arc4random_uniform(101)) < 50) {//returns number from 0 to 100 and checks to see if it is less than 50. If it is, than the helmut starts at the top
        shouldStartTop = YES;
        startY = game.contentSize.height + (self.contentSize.height * .5);
        endY = -self.contentSize.height;
    }

    else {

        shouldStartTop = NO;
        startY = -(self.contentSize.height * .5);
        endY = game.contentSize.height + self.contentSize.height;
    }

    self.position = ccp(startX, startY);
    [game addChild:self];

    ccBezierConfig bezier;
    bezier.controlPoint_1 = ccp (startX, startY);
    bezier.controlPoint_2 = ccp (endX, endY);
    bezier.endPosition    = ccp (endX, endY);

    id rotate =[CCRotateBy actionWithDuration:1.5f angle:360];
    id curve = [CCBezierTo actionWithDuration:1.5f bezier:bezier];
    id spawn = [CCSpawn actions:rotate, curve, nil];

    [self runAction:spawn];

    [self schedule:@selector(doneAnimating) interval:1.6];

}

- (void) doneAnimating{

    if ([[self delegate]respondsToSelector:@selector(helmetPastBounds:)]) {
        [[self delegate]helmetPastBounds:self];

    }
}

- (void) dealloc {

    CCLOG(@"%s", __PRETTY_FUNCTION__);

    [super dealloc];
}

@end

所以每秒调用一个这个类的新实例,这样屏幕上一次可以有多个头盔。然后我有另一种方法,在操作完成后稍微调用它以移除当前头盔并释放它。但是我遇到的问题是动作经常跳动/生涩,而 FPS 为 60。我是否需要对这些动作做一些不同的事情,或者是什么原因造成的?

4

0 回答 0