Cocos2d CCSprite Class Gets Image File Name

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, do you need to find out the name of the image file used for a particular CCSprite object later?

UPDATE 1:

The userData property looks interesting!

+5
source share
2 answers

No. CCSprite does not save the file name.

But, as you noticed, you can hang everything you want from the userData property - make sure that you manage your life correctly. Other options are to use a subclass or composition with CCSprite and other game classes so that you can track additional data.

+7
source

, :

GameSprite *spriteLogo = [GameSprite spriteWithFile:@"Logo.png"];
[spriteLogo setUserObject:@"Logo.png"];

, :

NSLog(@"%@", sprite.userObject);
+1

All Articles