Cocos2d doesn't have text controls, but you can easily add UIKit controls to the scene in Cocos2d 2.0
[[CCDirector sharedDirector] view] addSubview:myTextField];
You can use UIAlertView with an embedded text box.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil]; alert.alertViewStyle = UIAlertViewStylePlainTextInput; [alert show];
To receive events from a UIAlertView, you implement a UIAlertViewDelegate . In your header file, add the delegate protocol to your interface
@interface BTMyScene : CCLayer <UIAlertViewDelegate>
Then, in your implementation file, add any of the methods from the delegate protocol for which you want to receive notifications. You probably need this
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { UITextField *textField = [alertView textFieldAtIndex:0]; NSString *name = textField.text; }
I recommend reading the documentation for UIAlertView and UIAlertViewDelegate . You will see all the available methods that you can use.
source share