Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone CCRotateBy动作是否间歇性跳跃/急促?Cocos2d_Cocos2d Iphone_Ccaction - Fatal编程技术网

Cocos2d iphone CCRotateBy动作是否间歇性跳跃/急促?Cocos2d

Cocos2d iphone CCRotateBy动作是否间歇性跳跃/急促?Cocos2d,cocos2d-iphone,ccaction,Cocos2d Iphone,Ccaction,我有一个cpCCSprite的子类,它只用于使用chipmunk spaceManager,我的类如下所示: @implementation Helmet +(id) helmetWithGame:(Game*)game { return [[[self alloc] helmetInit:game] autorelease]; } - (id) helmetInit:(Game*)game { cpShape *helmet_1; cpShape *helme

我有一个cpCCSprite的子类,它只用于使用chipmunk 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
@实现头盔
+(id)头盔游戏:(游戏*)游戏{
返回[[[自我分配]头盔:游戏]自动释放];
}
-(id)头盔:(游戏*)游戏{
cpShape*头盔1;
cpShape*头盔2;
cpShape*头盔3;
cpShape*参考;
reference=[game.spaceManager addCircleAt:cpvzero-mass:STATIC_-mass-radius:2];
头盔1=[game.spaceManager addCircleToBody:reference->body radius:20 offset:cpv(-5,2)];
头盔2=[game.spaceManager addCircleToBody:reference->body radius:8 offset:cpv(16,-14)];
头盔3=[game.spaceManager addCircleToBody:reference->body radius:8 offset:cpv(8,-14)];
参考->组=1;
头盔1->组=1;
头盔2->组=1;
头盔3->组=1;
[self initWithFile:@“Helmet.png”];
[自选主体:参考->主体];
self.spaceManager=game.spaceManager;
self.autoFreeShapeAndBody=是;
gameScreenSize=game.contentSize;
回归自我;
}
-(无效)生成演示:(游戏*)游戏{
float startX=(float)((arc4random_uniform(101))+100);//返回从100到200的数字,并将其强制转换为float
浮星;
int endXRange=(game.contentSize.width*.8)-(game.contentSize.width*.5);
float endX=(float)((arc4random_uniform(endXRange))+(game.contentSize.width*.5));
浮动端;
布尔应该开始跳;
if((arc4random_uniform(101))<50{//返回0到100之间的数字,并检查其是否小于50。如果小于50,则helmut从顶部开始
shouldStartTop=是;
startY=game.contentSize.height+(self.contentSize.height*.5);
endY=-self.contentSize.height;
}
否则{
shouldStartTop=否;
startY=-(self.contentSize.height*.5);
endY=game.contentSize.height+self.contentSize.height;
}
自身位置=ccp(startX,startY);
[游戏添加孩子:自我];
ccbezier-config-bezier;
bezier.controlPoint_1=ccp(startX,startY);
bezier.controlPoint_2=ccp(endX,endY);
bezier.endPosition=ccp(endX,endY);
id旋转=[CCRotateBy Action with Duration:1.5f角度:360];
id曲线=[CCBezierToActionWithDuration:1.5f bezier:bezier];
id spawn=[CCSpawn操作:旋转、曲线、零];
[自我运行:繁殖];
[自调度:@selector(doneAnimating)间隔:1.6];
}
-(无效)不生效{
if([[self delegate]respondsToSelector:@selector(helmetPastBounds:)])){
[[self-delegate]头盔边界:self];
}
}
-(无效)解除锁定{
CCLOG(@“%s”,函数);
[super dealoc];
}
@结束

因此,每秒调用一个此类的新实例,这样屏幕上一次可以有多个头盔。然后,我有另一个方法,在acctions完成移除当前头盔并释放它之后,会稍微调用它。但我遇到的问题是,动作经常是跳跃/急促的,即FPS为60。我是否需要对动作做一些不同的处理,或者是什么导致了这种情况?

动作和物理相互作用?FPS是一个平均值。例如,当加载大纹理时,可能会以30 FPS的速度出现“一帧”倾斜。这是在设备还是模拟器中发生的(差别很大)?如果您怀疑纹理加载,可以尝试在开始此游戏序列之前使用纹理预加载纹理缓存-ymmv,确保在fps下降几乎不明显时执行此操作。fps下降发生在设备和模拟器上。@dqhendricks您能详细说明相互作用的动作和物理吗?Spacemanager将旋转精灵,您将使用CCRotateBy旋转精灵。我的猜测是:一个人大多数时候赢,但并不总是赢。我的第二个猜测是伊夫说的。检查ccConfig并将fps的平均时间降低到0.1甚至0.01,这样您甚至会注意到单个“漏帧”,尽管只是fps显示中的瞬间闪烁。