0

I have a method which sets up CCAnimation's for me

public CCAnimation SetupAnimations(string prefixOFSprite, int numberOfFrames, int startFrame)
    {
        //me getting desperate and doing any old initilisation
        CCAnimation finalAnimation = new CCAnimation();
        finalAnimation = CCAnimation.animation();

        for (int i = startFrame; i < numberOfFrames + 1; i++)
        {
            finalAnimation.addFrameWithFileName(prefixOFSprite + "-" + i);
        }

        float delay = 0.07f;
        finalAnimation.setDelay(delay);

        return finalAnimation;

Which I call like this

whiteDogBeginFalling = SetupAnimations("GameGraphics/dog/falling/white-falling", 7, 1)

But the animations don't play when I run the game :( This is me porting my game from iOS, and I got round this problem by adding

[whiteDogBeginFalling retain]

straight after the method call.

How do you do this in the C# version of cocos2d? Or can anyone help me come up with another solution?

Thanks in advance

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
user819640
  • 250
  • 5
  • 14

1 Answers1

1

"getting around a problem by adding retain" sounds like you did not understand ObjC memory management (at that time).

I would investigate the possibility that the retain in the ObjC code is wrong to begin with. Since there's no retain in C# and the object apparently is released in C#, it means there are no references holding on to the object, therefore it will be garbage collected. Which indicates that the retain in the ObjC version fixed your issue of releasing the object, but you may have a memory leak there.

If you can figure out how to fix the issue correctly in ObjC, you'll also know what to do to fix it in the C# version.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thanks for the help. I have tried playing the animation from the main game class and it works great, it seems to be the only problem is when I try to run the animation from the AnimalClass (I pass it to the class through a method). It inherits CCNode and has sprites to run the animation, so why would garbage collection be clearing it on me? – user819640 Mar 17 '12 at 12:55