Cocos2d iphone 具有动画精灵表plist的Box2D实体
我已经使用CCSpriteBatchNode和CCSprite创建了一个动画精灵。我使用plist获取帧。这是我放在init()中的代码 创建主体后,在构建和运行时,程序在第行崩溃Cocos2d iphone 具有动画精灵表plist的Box2D实体,cocos2d-iphone,box2d,sprite,ccsprite,Cocos2d Iphone,Box2d,Sprite,Ccsprite,我已经使用CCSpriteBatchNode和CCSprite创建了一个动画精灵。我使用plist获取帧。这是我放在init()中的代码 创建主体后,在构建和运行时,程序在第行崩溃 frameBody = _world->CreateBody(&frameBodyDef); 说访问权限不好 请在这方面帮助我,为什么动画精灵不能添加到身体 谢谢。这是我想出的解决办法 如果从plist创建精灵工作表,并希望将动画工作表添加到身体,请确保首先将精灵对象添加到身体,然后将精灵添加到工作表
frameBody = _world->CreateBody(&frameBodyDef);
说访问权限不好
请在这方面帮助我,为什么动画精灵不能添加到身体
谢谢。这是我想出的解决办法 如果从plist创建精灵工作表,并希望将动画工作表添加到身体,请确保首先将精灵对象添加到身体,然后将精灵添加到工作表 这是正确的代码
//================== making animating sprite
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"framelist.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"frames.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"frame%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.1f];
//_frameSprite is CC Sprite
_frameSprite = [CCSprite spriteWithBatchNode:spriteSheet
rect:CGRectMake(0,0,48,48)];
_frameSprite.position = ccp(winSize.width + 60, winSize.height/2);
_flyAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[_frameSprite runAction:_flyAction];
b2BodyDef frameBodyDef;
frameBodyDef.type = b2_staticBody;
frameBodyDef.position.Set(160/PTM_RATIO, 200/PTM_RATIO);
frameBodyDef.userData = _frameSprite; //================first add the sprite to body
frameBody = _world->CreateBody(&frameBodyDef);
[spriteSheet addChild:_frameSprite]; //======second add sprite to the sheet
制作动画精灵
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@“framelist.plist”];
CCSpriteBatchNode*spriteSheet=[CCSpriteBatchNode
batchNodeWithFile:@“frames.png”];
[自添加子项:精灵表];
NSMutableArray*walkAnimFrames=[NSMutableArray];
对于(int i=1;i CreateBody(&frameBodyDef);
[spriteSheet addChild:_frameSprite];/====第二次将sprite添加到工作表
这是我找到的解决方案 如果从plist创建精灵工作表,并希望将动画工作表添加到身体,请确保首先将精灵对象添加到身体,然后将精灵添加到工作表 这是正确的代码
//================== making animating sprite
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"framelist.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"frames.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"frame%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.1f];
//_frameSprite is CC Sprite
_frameSprite = [CCSprite spriteWithBatchNode:spriteSheet
rect:CGRectMake(0,0,48,48)];
_frameSprite.position = ccp(winSize.width + 60, winSize.height/2);
_flyAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[_frameSprite runAction:_flyAction];
b2BodyDef frameBodyDef;
frameBodyDef.type = b2_staticBody;
frameBodyDef.position.Set(160/PTM_RATIO, 200/PTM_RATIO);
frameBodyDef.userData = _frameSprite; //================first add the sprite to body
frameBody = _world->CreateBody(&frameBodyDef);
[spriteSheet addChild:_frameSprite]; //======second add sprite to the sheet
制作动画精灵
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@“framelist.plist”];
CCSpriteBatchNode*spriteSheet=[CCSpriteBatchNode
batchNodeWithFile:@“frames.png”];
[自添加子项:精灵表];
NSMutableArray*walkAnimFrames=[NSMutableArray];
对于(int i=1;i CreateBody(&frameBodyDef);
[spriteSheet addChild:_frameSprite];/====第二次将sprite添加到工作表
变量“世界”是否正确初始化?变量“世界”是否正确初始化?
//================== making animating sprite
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"framelist.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"frames.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"frame%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.1f];
//_frameSprite is CC Sprite
_frameSprite = [CCSprite spriteWithBatchNode:spriteSheet
rect:CGRectMake(0,0,48,48)];
_frameSprite.position = ccp(winSize.width + 60, winSize.height/2);
_flyAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[_frameSprite runAction:_flyAction];
b2BodyDef frameBodyDef;
frameBodyDef.type = b2_staticBody;
frameBodyDef.position.Set(160/PTM_RATIO, 200/PTM_RATIO);
frameBodyDef.userData = _frameSprite; //================first add the sprite to body
frameBody = _world->CreateBody(&frameBodyDef);
[spriteSheet addChild:_frameSprite]; //======second add sprite to the sheet