Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ipadzero

macrumors newbie
Original poster
Oct 23, 2011
7
0
Hi, I want to display the tag name of my CCSprite

For example
CCSprite* abc = ............;
abc.tag = Sprite1Tag;

Is there any way to use NSString to display the name "Sprite1Tag"

Thanks a lot
 

Matthew Yohe

macrumors 68020
Oct 12, 2006
2,200
142
Hi, I want to display the tag name of my CCSprite

For example
CCSprite* abc = ............;
abc.tag = Sprite1Tag;

Is there any way to use NSString to display the name "Sprite1Tag"

Thanks a lot

Uhm, could you provide more of an explanation of what you want?

The tag on a CSSprite is an integer, and so... it's not very clear what you really want here.

If you just want to print the tag, you can log it: NSLog(@"tag: %d",abc.tag);
 

ipadzero

macrumors newbie
Original poster
Oct 23, 2011
7
0
Uhm, could you provide more of an explanation of what you want?

The tag on a CSSprite is an integer, and so... it's not very clear what you really want here.

If you just want to print the tag, you can log it: NSLog(@"tag: %d",abc.tag);

Thanks for your quick reply,
I want to use a label control to show the tag name of my sprite in the top left corner when I touch it , your code is only show the tag number, what I want to show here is "Sprite1Tag"
 

Matthew Yohe

macrumors 68020
Oct 12, 2006
2,200
142
Thanks for your quick reply,
I want to use a label control to show the tag name of my sprite in the top left corner when I touch it , your code is only show the tag number, what I want to show here is "Sprite1Tag"

Oh, so then just NSLog(@"Sprite%dTag",abc.tag);
 

Matthew Yohe

macrumors 68020
Oct 12, 2006
2,200
142
"Sprite1Tag" is just an example, my tag name can be anything, won't follow that format

Uhm, then you haven't really told me what you want.

Please be very explicit, you're not being so.

Give me real examples of what you want to occur.

----------

"Sprite1Tag" is just an example, my tag name can be anything, won't follow that format

And also, remember your tag can only be a number, not a string. So, it can't be "anything"
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Hi, I want to display the tag name of my CCSprite

For example
Code:
CCSprite* abc = ............;
abc.tag = Sprite1Tag;

Is there any way to use NSString to display the name "Sprite1Tag"

Thanks a lot

In this code, Spring1Tag is not an NSString. It's an identifier and it doesn't exist after your code is compiled. So there's nothing you can directly do to print that identifier when your program runs.

However there are other techniques for doing this. One technique is to maintain an array of the sprite name (as NSString objects) and then set the sprite's tag to be the index of the name in that array.
 

ipadzero

macrumors newbie
Original poster
Oct 23, 2011
7
0
Uhm, then you haven't really told me what you want.

Please be very explicit, you're not being so.

Give me real examples of what you want to occur.

----------



And also, remember your tag can only be a number, not a string. So, it can't be "anything"

My example is in my 2nd post. Sorry if I didn't explain it clearly

In this code, Spring1Tag is not an NSString. It's an identifier and it doesn't exist after your code is compiled. So there's nothing you can directly do to print that identifier when your program runs.

However there are other techniques for doing this. One technique is to maintain an array of the sprite name (as NSString objects) and then set the sprite's tag to be the index of the name in that array.

Hmm, so I guess there's no other way can do that directly.
Thanks all
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Hmm, so I guess there's no other way can do that directly.
Thanks all

The problem with your post was that you took a well known problem of the C, C++, Objective-C, Java and other languages, and hid it away in a context with language that made it very hard to find out what you wanted. When you ask for help, remember that nobody can read your mind, so you have to pose your question in a very clear way. (BTW. Quite often that alone makes it unnecessary to ask).

I tend to write a class method "stringForTag:(NSInteger)tag" which converts enum values to strings with a switch statement.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.