看来我的角色似乎使用 CCAnimation 和 Cocoa2d 3.x 按预期制作动画。问题是当我将 CCAnimatedSprite 设置为具有physicsBody 时,就像我之前的 CCSprite 所做的那样,我遇到了崩溃
Aborting due to Chipmunk error: Body's moment is NaN.
Failed condition: body->i == body->i && body->i_inv == body->i_inv
Source:/Users/Jason/Desktop/RPGGame/RPG/Libraries/Chipmunk/chipmunk/src/cpBody.c:114
但是,如果我删除这一行:
mainChar.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, mainChar.contentSize} cornerRadius:0];
崩溃消失了,但物理并没有应用于我的 CCAnimatedSprite,我该如何解决这个问题,为什么这条线会导致它?
初始化我的 CCAnimatedSprite 的完整代码:
CCTiledMapObjectGroup *objects0 = [levelOneMap objectGroupNamed:@"mainChar"];
NSMutableDictionary *startPoint0 = [objects0 objectNamed:@"startPosition"];
int x0 = [[startPoint0 valueForKey:@"x"] intValue];
int y0 = [[startPoint0 valueForKey:@"y"] intValue];
self.mainChar = [CCAnimatedSprite animatedSpriteWithPlist:@"AnimateChar.plist"];
mainChar.position = ccp(x0,y0);
mainChar.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, mainChar.contentSize} cornerRadius:0];
mainChar.physicsBody.collisionGroup = @"groupPlayer";
mainChar.physicsBody.collisionType = @"collisionPlayer";
[mainChar addAnimationwithDelayBetweenFrames:0.1f name:@"AnimateChar"];
[mainChar setFrame:@"AnimateChar-1.png"];
[self.physicsWorldNode addChild: mainChar];