本文介绍了播放来自另一类的cocos2d动画的奇怪问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的事情.如果有人可以,请帮助我.它的三天,我想我将被解雇:(

strange thing. if someone could please,please help me. its 3 days, and i think i am going to be fired :(

我有带有动画功能的cocos2d类和另一个xcode类.如果我从cocos2d类的init函数调用动画函数,则在启动应用程序时正在播放动画.

i have cocos2d class with animation function,and another xcode class.if i call from the cocos2d class init function to animation function, the animation is being played when app is starts.

如果我从另一个类调用cocos2d类动画,那么它会执行init函数并输入动画,但是我看不到它在播放.

if i call from another class to the cocos2d class-animation, so it does the init function and enter the animation,but i cant see it playing.

因此,仅当仅在cocos类中调用该动画时,该动画才起作用.为什么?

so the animation is working only if called from within the cocos class only.WHY ?

这就是我所说的动画:

ran=[[HelloWorld alloc] init];
    [ran animation];

这是动画:

-(void)animation
{
    //[self removeChild:background cleanup:YES];
    //[b_pic.parent removeChild:b_pic cleanup:YES];



    //animation
    CCSpriteBatchNode *danceSheet = [ CCSpriteBatchNode batchNodeWithFile:@"head.png"]; 
    [self addChild:danceSheet];

    CCSprite *danceSprite = [CCSprite spriteWithTexture:danceSheet.texture rect:CGRectMake(0, 0, 480, 320)];
    [danceSheet addChild:danceSprite];
    //danceSprite.anchorPoint=CGPointMake(0, 0);

    CGSize s = [[CCDirector sharedDirector] winSize];
    danceSprite.position = ccp(s.width/2,s.height/2);

    CCAnimation *danceAnimation = [CCAnimation animation];
    [danceAnimation setDelay:0.1f];

    int frameCount = 0;
    for (int y = 0; y < 4; y++) 
    {
        NSLog(@"%@",animation);
        for (int x = 0; x < 5; x++) 
        {
            CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:danceSheet.texture rect:CGRectMake(x*320,y*440,320,440)];
            [danceAnimation addFrame:frame];

            frameCount++;

            if (frameCount == 25)
                break;
        }
    }

推荐答案

解决了,我不知道为什么.

solved , and i dont know why.

但是如果要从外部调用cocos2d函数,则必须执行以下操作:

but if you want to call a cocos2d function from the outside, you have to do :

[(HelloWorld*)[[[CCDirector sharedDirector] runningScene] getChildByTag:42] HardwareEvent:DollPart];

并像这样标记您的图层:

and tag your layer like :

 layer.tag=42;

现场方法!

那是它运作良好的唯一途径.

thats the only way it works great.

这篇关于播放来自另一类的cocos2d动画的奇怪问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:09