cocos2d 精灵动画不显示 sheet
cocos2d animation not showing of sprite sheet
我的游戏出现了一些奇怪的错误。谁能帮我解决这个问题。
我有一个跑步游戏,英雄在 运行 时收集硬币,当英雄触摸硬币时,现在我正在展示在粒子 maker.and 的帮助下创建的粒子效果,它工作正常。但是昨天我买了一个软件,它给了我们非常好的粒子效果,但它只能导出为 pngs
。所以我制作了 sprite sheet 而不是以前的粒子动画,我把它放在接触侦听器代码上,以便在英雄触摸硬币时显示这种效果。不幸的是它没有显示任何东西。这是我以前的代码:
-(void) checkHeroAndCoins {
float fDelta = 0;
if(m_hero->m_bMagnet)
fDelta = iDevPixelX(30);
for(Coin *coin in m_drawLayer.children){
if([coin isKindOfClass:[Coin class]]){
CGRect rCoin = CGRectMake(coin.position.x - coin.contentSize.width * coin.scaleX / 2.0f - fDelta,
coin.position.y - coin.contentSize.height * coin.scaleY / 2.0f - fDelta,
coin.contentSize.width * coin.scaleX + fDelta * 2, coin.contentSize.height * coin.scaleY + fDelta * 2);
CGRect rHero = CGRectMake(m_hero.position.x - m_hero.contentSize.width * m_hero.scaleX / 2.0f, m_hero.position.y, m_hero.contentSize.width * m_hero.scaleX, m_hero.contentSize.height * m_hero.scaleY);
if(CGRectIntersectsRect(rCoin, rHero)){
coin.tag = DELETED_TAG;
g_nCoin++;
[[AppDelegate getDelegate] playSystemEffect:E_COIN];
// this below code is to show the particle effect and its working perfect
CCParticleSystem *effect = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"arroweffect.plist"];
[self addChild:effect];
effect.position = ccp(self.contentSize.width * self.scaleX / 2, self.contentSize.height * self.scaleY / 2.0f);
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
effect.scale *= 2;
}
}
}
[[AppDelegate getDelegate] saveSetting];
}
但是我把spritesheet做成动画显示效果后,就不行了,我尽力了也没能解决这个问题。这是我的代码 sprite sheet animation
:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"coinsprite.plist"];
//load the sprite sheet into a CCSpriteBatchNode object. If you're adding a new sprite
//to your scene, and the image exists in this sprite sheet you should add the sprite
//as a child of the same CCSpriteBatchNode object otherwise you could get an error.
CCSpriteBatchNode *parrotSheet12 = [CCSpriteBatchNode batchNodeWithFile:@"coinsprite.png"];
//add the CCSpriteBatchNode to your scene
[self addChild:parrotSheet12];
//load each frame included in the sprite sheet into an array for use with the CCAnimation object below
NSMutableArray *flyAnimFrames12 = [NSMutableArray array];
for(int i = 1; i <=30; ++i) {
[flyAnimFrames12 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"coins%04d.png", i]]];
}
//Create the animation from the frame flyAnimFrames array
CCAnimation *flyAnim12 = [CCAnimation animationWithFrames:flyAnimFrames12 delay:1.0f];
//create a sprite and set it to be the first image in the sprite sheet
CCSprite * dragont2 = [CCSprite spriteWithSpriteFrameName:@"coins0000.png"];
//set its position to be dead center, i.e. screen width and height divided by 2
[dragont2 setPosition:ccp(600,600)];
//[self moveRandom:theParrot];
//create a looping action using the animation created above. This just continuosly
//loops through each frame in the CCAnimation object
CCAction *flyAction12 = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:flyAnim12 restoreOriginalFrame:NO]];
//start the action
[dragont2 runAction:flyAction12];
//add the sprite to the CCSpriteBatchNode object
[parrotSheet12 addChild:dragont2];
问题已解决
-(void) coinanimationeffect:(CGPoint) ptPos {
m_gamecoinffect = [CCSprite spriteWithSpriteFrameName:@"coins0001.png"];
[self addChild:m_gamecoinffect];
CCAnimate *coineffect = [CCAnimate actionWithSpriteSequence:@"coins%04d.png" numFrames:30 delay:0.01f restoreOriginalFrame:NO];
[m_gamecoinffect runAction:[CCRepeatForever actionWithAction:coineffect]];
m_gamecoinffect.position = ptPos;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
m_gamecoinffect.scale *= 2;
}
添加了这个功能
并在
中调用该函数
-(void) checkHeroAndCoins {
float fDelta = 0;
if(m_hero->m_bMagnet)
fDelta = iDevPixelX(30);
for(Coin *coin in m_drawLayer.children){
if([coin isKindOfClass:[Coin class]]){
CGRect rCoin = CGRectMake(coin.position.x - coin.contentSize.width * coin.scaleX / 2.0f - fDelta,
coin.position.y - coin.contentSize.height * coin.scaleY / 2.0f - fDelta,
coin.contentSize.width * coin.scaleX + fDelta * 2, coin.contentSize.height * coin.scaleY + fDelta * 2);
CGRect rHero = CGRectMake(m_hero.position.x - m_hero.contentSize.width * m_hero.scaleX / 2.0f, m_hero.position.y, m_hero.contentSize.width * m_hero.scaleX, m_hero.contentSize.height * m_hero.scaleY);
if(CGRectIntersectsRect(rCoin, rHero)){
coin.tag = DELETED_TAG;
g_nCoin++;
[[AppDelegate getDelegate] playSystemEffect:E_COIN];
[self coinanimationeffect:ccp(coin.position.x, coin.position.y)];
}
}
}
[[AppDelegate getDelegate] saveSetting];
}
我的游戏出现了一些奇怪的错误。谁能帮我解决这个问题。
我有一个跑步游戏,英雄在 运行 时收集硬币,当英雄触摸硬币时,现在我正在展示在粒子 maker.and 的帮助下创建的粒子效果,它工作正常。但是昨天我买了一个软件,它给了我们非常好的粒子效果,但它只能导出为 pngs
。所以我制作了 sprite sheet 而不是以前的粒子动画,我把它放在接触侦听器代码上,以便在英雄触摸硬币时显示这种效果。不幸的是它没有显示任何东西。这是我以前的代码:
-(void) checkHeroAndCoins {
float fDelta = 0;
if(m_hero->m_bMagnet)
fDelta = iDevPixelX(30);
for(Coin *coin in m_drawLayer.children){
if([coin isKindOfClass:[Coin class]]){
CGRect rCoin = CGRectMake(coin.position.x - coin.contentSize.width * coin.scaleX / 2.0f - fDelta,
coin.position.y - coin.contentSize.height * coin.scaleY / 2.0f - fDelta,
coin.contentSize.width * coin.scaleX + fDelta * 2, coin.contentSize.height * coin.scaleY + fDelta * 2);
CGRect rHero = CGRectMake(m_hero.position.x - m_hero.contentSize.width * m_hero.scaleX / 2.0f, m_hero.position.y, m_hero.contentSize.width * m_hero.scaleX, m_hero.contentSize.height * m_hero.scaleY);
if(CGRectIntersectsRect(rCoin, rHero)){
coin.tag = DELETED_TAG;
g_nCoin++;
[[AppDelegate getDelegate] playSystemEffect:E_COIN];
// this below code is to show the particle effect and its working perfect
CCParticleSystem *effect = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"arroweffect.plist"];
[self addChild:effect];
effect.position = ccp(self.contentSize.width * self.scaleX / 2, self.contentSize.height * self.scaleY / 2.0f);
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
effect.scale *= 2;
}
}
}
[[AppDelegate getDelegate] saveSetting];
}
但是我把spritesheet做成动画显示效果后,就不行了,我尽力了也没能解决这个问题。这是我的代码 sprite sheet animation
:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"coinsprite.plist"];
//load the sprite sheet into a CCSpriteBatchNode object. If you're adding a new sprite
//to your scene, and the image exists in this sprite sheet you should add the sprite
//as a child of the same CCSpriteBatchNode object otherwise you could get an error.
CCSpriteBatchNode *parrotSheet12 = [CCSpriteBatchNode batchNodeWithFile:@"coinsprite.png"];
//add the CCSpriteBatchNode to your scene
[self addChild:parrotSheet12];
//load each frame included in the sprite sheet into an array for use with the CCAnimation object below
NSMutableArray *flyAnimFrames12 = [NSMutableArray array];
for(int i = 1; i <=30; ++i) {
[flyAnimFrames12 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"coins%04d.png", i]]];
}
//Create the animation from the frame flyAnimFrames array
CCAnimation *flyAnim12 = [CCAnimation animationWithFrames:flyAnimFrames12 delay:1.0f];
//create a sprite and set it to be the first image in the sprite sheet
CCSprite * dragont2 = [CCSprite spriteWithSpriteFrameName:@"coins0000.png"];
//set its position to be dead center, i.e. screen width and height divided by 2
[dragont2 setPosition:ccp(600,600)];
//[self moveRandom:theParrot];
//create a looping action using the animation created above. This just continuosly
//loops through each frame in the CCAnimation object
CCAction *flyAction12 = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:flyAnim12 restoreOriginalFrame:NO]];
//start the action
[dragont2 runAction:flyAction12];
//add the sprite to the CCSpriteBatchNode object
[parrotSheet12 addChild:dragont2];
问题已解决
-(void) coinanimationeffect:(CGPoint) ptPos {
m_gamecoinffect = [CCSprite spriteWithSpriteFrameName:@"coins0001.png"];
[self addChild:m_gamecoinffect];
CCAnimate *coineffect = [CCAnimate actionWithSpriteSequence:@"coins%04d.png" numFrames:30 delay:0.01f restoreOriginalFrame:NO];
[m_gamecoinffect runAction:[CCRepeatForever actionWithAction:coineffect]];
m_gamecoinffect.position = ptPos;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
m_gamecoinffect.scale *= 2;
}
添加了这个功能
并在
中调用该函数-(void) checkHeroAndCoins {
float fDelta = 0;
if(m_hero->m_bMagnet)
fDelta = iDevPixelX(30);
for(Coin *coin in m_drawLayer.children){
if([coin isKindOfClass:[Coin class]]){
CGRect rCoin = CGRectMake(coin.position.x - coin.contentSize.width * coin.scaleX / 2.0f - fDelta,
coin.position.y - coin.contentSize.height * coin.scaleY / 2.0f - fDelta,
coin.contentSize.width * coin.scaleX + fDelta * 2, coin.contentSize.height * coin.scaleY + fDelta * 2);
CGRect rHero = CGRectMake(m_hero.position.x - m_hero.contentSize.width * m_hero.scaleX / 2.0f, m_hero.position.y, m_hero.contentSize.width * m_hero.scaleX, m_hero.contentSize.height * m_hero.scaleY);
if(CGRectIntersectsRect(rCoin, rHero)){
coin.tag = DELETED_TAG;
g_nCoin++;
[[AppDelegate getDelegate] playSystemEffect:E_COIN];
[self coinanimationeffect:ccp(coin.position.x, coin.position.y)];
}
}
}
[[AppDelegate getDelegate] saveSetting];
}