Get text of CCLabelTTF - iphone

I have multiple scenes in my iphone game. In one of the scene which is the SelectLevelMenu scene I have shown the level number in a CCLabelTTF. Now I want to use this value in my StartGame scene which will run according to the value I got from the label.
However, I am unable to get the text of label. Once I get this value, I can assign it to a variable which I can use to switch levels.
All I want is how to get the text of CCLabelTTF.
Thanks

Use NSString *str = [cclabelTTFObj string];

Related

cocos2d I want my image is displayed once

I have an application cocos2d. I want my image is displayed once. Not every time I go in cocos2d view.Do you have any idea?
Just use a global flag for this. Create a bool variable globally and set it False after display image. And check this variable each time entering that view. If it is false you can remove that image from view or set it's opacity to zero if you want to display that image in any other cases.
this ques is not explicitly related to cocos2d though.
Steps:
1. When you need to display ur image, check for a bool value existence in NSUserDefaults.
2. If value does not exists (or return value is FALSE), means you can display your image.
3. After displaying image, set TRUE value in NSUserDefaults for that specific key.
Done..!!

Update UILabel with Global NSString

In my delegate i have an NSInteger healthInt; and NSMutableString * healthString. In appDelegate.m i have set healthString to hold the changing value of healthInt. Then in a different view i have UILabel * healthLabel. And I have set healthLabel to display healthString with the following code.
healthLabel.text = [NSString stringWithFormat:#"%#", appDelegate.healthString];
This works and displays the number 100, which is what i have set healthInt to in the appDelegate. But when a UIImageView mainSprite collides with a different ImageView healthInt should decrease by two. Which it does, i can tell because i can see it happen in the log. The log may change and display the values of the slowly decreasing healthInt, but the healthLabel doesn't update as healthInt decreases. My question is how can i get this healthLabel to update as healthInt decreases? I have tried just putting in that code for the collision detection between mainSprite and the other ImageView that causes damage but that doesn't seem to work. Thanks!
If you want to get your UILabel to update every time healthInt or healthString changes, there's a couple ways to do this.
One way is to go into the setter method for healthInt (or create one instead of using #synthesize) and broadcast a NSNotification for each time your healthInt number changes. And then when the view with that label is visible, have an observer registered pick up on that notification and make a change to your label.
Another way is to use Key Value Coding & bind the UILabel's text field to healthString. Here is a related question that may help you use this possible solution.

Remove labels using WhirlyGlobe

I am using the (really cool) WhirlyGlobe (https://code.google.com/p/whirlyglobe/) 3D globe display for iPhone in a new application. I can add labels at certain locations using the code shown below. I want to be able to go back and remove a label I added earlier. The Documentation (http://whirlyglobedocs.s3-website-us-east-1.amazonaws.com/html/interface_label_layer.html#ac17e1ec72e70eec416cb2cac833f46fa) shows a removeLabel method but I cannot seem to get it to work. I can add but not remove Labels. I tried looping through all subviews but cannot find these SimpleLabel instances. Can someone please help me understand how to remove a label? I haven't had much luck finding many examples. Thank you!
// Current position
float lat = [[values objectAtIndex:8] floatValue];
flaot lon = [[values objectAtIndex:9] floatValue];
// Create a SingleLabel at this Lat / Lon pair location
SingleLabel *interimLabel = [[[SingleLabel alloc] init] autorelease];
interimLabel.text = [NSString stringWithFormat:#"PRN %d",[[values objectAtIndex:1] intValue]];
[interimLabel setLoc:GeoCoord::CoordFromDegrees(lon, lat)];
[locationArray addObject:interimLabel];
[allLabels addObject:interimLabel];
When you add a single label or a group of labels to the label layer, you'll get back a SimpleIdentity. Keep that around somewhere. Then, when you want to delete the label (or group of labels) from the label layer, you pass back in that SimpleIdentity.
What's going on is this. WhirlyGlobe batches drawable data like a mofo. Your SingleLabel objects no longer exist as soon as the Label Layer has crunched them down into as few Drawables and it can get away with. So to refer to those labels, you have to keep around the unique ID.
Now if you want to delete these labels separately or individually change their appearances, then you've got to add them one by one. One label to one SimpleIdentity. Otherwise there's no way to refer to them individually.
For speed, I recommend grouping as many of them together as you can get away with. If that's just too complex for now, add them one by one and then make a note to come back. So when you say "Why isn't this running as fast as I'd like" you can then say "Ooooo, right."

UITextView or UIWebView: How to display pages of a simple editable TXT file

All I want to have is a full-screen simple text editor. However, I don't want the scrolling component, but rather let the user flick through the pages (instead of scrolling). So I need to import or open a TXT and then format it by braking it down (e.g. by dividing its contents to 10 lines per screen/page).
My question is how I will display the txt? UITextView is scrollable (even though I can disable this in IB)... I did not find any method for UIWebView to let it format my contents on different 'pages' or screens.
Where will I need to start? Ideally I'd need some sample code. All the samples for UIWebView do not tell me anything about how to format editable text on several pages.
So all I really want is an UITextView which is not scrollable and opens up a new page/screen if I run out of space on the first page/screen.
Thanks for any help to get me started.
first thing first ...... there is no particular method to achieve this
1.You need to break your single string into multiple strings, to do that you can use
int pageNumber; // suppose this keep track of on what page you are
int count; //suppose this keep track of how long string your one screen support
NSString* completeString; //suppose this is your string
NSRange range = NSMakeRange(pageNumber * count, count);
NSString* temp = [completeString substringWithRange:range];
2.Now instead of using UITextView (if you don't want user interaction ) you should use UILable
just change the property of UILabel (this one is of your interest)
UILabel* myLabel; //suppose this is that label
myLabel.numberOfLines = 0; //this will chage your label to go multyline.
You should be able to achieve this by putting your UITextView into a UIScrollView and setting pagingEnabled on the UIScrollView to YES.

How to get current value of UITextField in cocos2d 0.8.2?

Hi all I am using cocos2d 0.8.2 for my new game. I have added a UITextField in my game and on click of a button (this button is actually a sprite i m using ccTouchesEnded! ) i save text field's value in database, but whenever i access the value i am getting nil. if i initialize the textfield value by some string, it always give me only that value.
i.e.
[txtField setText:#"Enter Your Name"];
when i access the value of txtField on a click of button it always give me "Enter Your Name". Although the value is changing when i type in textField, but its not returning me the new value.
is this a issue with cocos2d 0.8.2 or i am missing something?
You don't save the entered text. You just set #"Enter your Name" as default text, that is displayed in the cell. You should have a look at the UITextFieldDelegate methods. You have to overwrite the method didEndEditing, that is called after your editing or typing in text has ended, and implement there a line that saves the current value. Here you can use something like this:
NSString *containerForTextFieldValue = textField.text;