Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos2d CCSprite Class get the name of the image file

I can initialize or create a new CCSprite object using the following code:

NSString *fileName = [[imagesPath objectAtIndex:i] lastPathComponent];
        CCSprite *sprite = [CCSprite spriteWithFile:fileName];

Now, is there anyway to later find out the name of the image file used for the particular CCSprite object?

UPDATE 1:

userData property looks interesting!

like image 481
azamsharp Avatar asked Sep 06 '10 19:09

azamsharp


1 Answers

No. CCSprite is not retaining the filename.

But like you noticed, you can hang whatever you want off the userData property -- make sure you manage its lifetime properly. Other options are to use subclassing or composition with CCSprite and your other game classes so that you can keep track of additional data.

like image 139
Hitesh Avatar answered Sep 27 '22 21:09

Hitesh