菜鸟教程小白 发表于 2022-12-11 18:14:10

ios - cocos2d 动画不显示 Sprite 表


                                            <p><p>我的游戏发生了一些奇怪的错误。任何人都可以帮助我解决这个问题。
我有一个运行游戏,英雄在运行时收集硬币,当英雄接触硬币时,现在我正在展示在粒子制造器的帮助下创建的粒子效果。它工作正常。但是昨天我买了一个软件,它给了我们非常好的粒子效果,但它只能导出为 <code>pngs</code>。所以我制作了 Sprite 表,而不是之前的粒子动画,我把它放在了接触监听器代码中,以便在英雄接触硬币时显示这种效果。不幸的是,它没有显示任何东西。这是我之前的代码:</p>

<pre><code>-(void) checkHeroAndCoins {
float fDelta = 0;
if(m_hero-&gt;m_bMagnet)
    fDelta = iDevPixelX(30);

for(Coin *coin in m_drawLayer.children){
    if(]){
      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++;
            [ playSystemEffect:E_COIN];
// this below code is to show the particle effect and its working perfect
            CCParticleSystem *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;



      }
    }
}
[ saveSetting];
}
</code></pre>

<p>但是在我将 Sprite 表作为动画显示效果后,它不起作用,我尽了最大努力但无法解决这个问题。这是我的 <code>sprite sheet 动画</code>代码:</p>

<pre><code>[ addSpriteFramesWithFile: @&#34;coinsprite.plist&#34;];

//load the sprite sheet into a CCSpriteBatchNode object. If you&#39;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 = ;



//add the CCSpriteBatchNode to your scene

;


//load each frame included in the sprite sheet into an array for use with the CCAnimation object below

NSMutableArray *flyAnimFrames12 = ;

for(int i = 1; i &lt;=30; ++i) {

    [flyAnimFrames12 addObject:

   [ spriteFrameByName:

      ]];

}

//Create the animation from the frame flyAnimFrames array

CCAnimation *flyAnim12 = ;

//create a sprite and set it to be the first image in the sprite sheet

CCSprite * dragont2 = ;

//set its position to be dead center, i.e. screen width and height divided by 2

;

//;
//create a looping action using the animation created above. This just continuosly

//loops through each frame in the CCAnimation object

CCAction *flyAction12 = [CCRepeatForever actionWithAction:

                         ];

//start the action

;

//add the sprite to the CCSpriteBatchNode object

;
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>问题解决了</p>

<pre><code>-(void) coinanimationeffect:(CGPoint) ptPos {
m_gamecoinffect = ;
;



CCAnimate *coineffect = ;
];

m_gamecoinffect.position = ptPos;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    m_gamecoinffect.scale *= 2;
</code></pre>

<p>}</p>

<p>添加了这个功能</p>

<p>并在 </p> 中调用该函数

<pre><code>-(void) checkHeroAndCoins {
float fDelta = 0;
if(m_hero-&gt;m_bMagnet)
    fDelta = iDevPixelX(30);

for(Coin *coin in m_drawLayer.children){
    if(]){
      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++;
            [ playSystemEffect:E_COIN];



         ;






      }
    }
}
[ saveSetting];
</code></pre>

<p>}</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - cocos2d 动画不显示 Sprite 表,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40927068/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40927068/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - cocos2d 动画不显示 Sprite 表