replacing a CCSprite with another: memory leaks?

Member
Posts: 164
Joined: 2010.10
Post: #1
I have a HellpWorld template.
i have a CCNode with a variable:

Code:
CCSprite *a;//in header

with an init function
Code:
a=[CCSprite spriteWithFile:"a.png"];
added the CCNode as child in helloworld.m init

if i want to replace the image with another one using always a.
i have a method inside the CCNode that makes:
Code:
a=[CCSprite spriteWithFile:"b.png"];
but nothing happens...
Code:
[a release];
a=[CCSprite spriteWithFile:"b.png"];
make it crash...
so i've tryed:
Code:
[a setTexture: [[CCTexture2D alloc] initWithImage:[UIImage imageNamed: @"b.png"]];
and it works, but i think it will have memory leaks because i have used alloc. correct me if i'm wrong.

but i don't know how to release the texture before loading another.
and why:
Code:
a=[CCSprite spriteWithFile:"b.png"]
doesnt work?
thanks
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
the CCTextureCache handles the management of releasing and allocating textures.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #3
thanks i'll try
Quote this message in a reply
Post Reply