cocos2dのメニューを使ってゲームの設定シーンを作ったのですが、ユーザーが数値を入力できるようにしたいです。
メニューは複数の選択肢がある場合に最適ですが、ユーザーが数値を入力するための値ボックスやその他の方法を追加するにはどうすればよいですか。
cocos2dのメニューを使ってゲームの設定シーンを作ったのですが、ユーザーが数値を入力できるようにしたいです。
メニューは複数の選択肢がある場合に最適ですが、ユーザーが数値を入力するための値ボックスやその他の方法を追加するにはどうすればよいですか。
1 つの方法は、cocos2d シーンで UIKit 要素を使用することです (はい、それらを混在させることができます)。特に、ゲーム レイヤーで UITextField を使用できます。
@interface MyLayer : CCLayer<UITextFieldDelegate> {
UITextField *myTextField;
}
次に、MyLayer.m の init 関数で:
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(..,..,..,..)];
myTextField.delegate = self; //set the delegate of the textfield to this layer
[myTextField becomeFirstResponder];
// Configure some of your textfield properties as appropriate...
[myTextField.keyboardType = UIKeyboardTypeDefault;
[myTextField.returnKeyType = UIReturnKeyDone;
[myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
[myTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
[[[CCDirector sharedDirector] openGLView] addSubview: myTextField];
以下を実装することにより、ユーザーが完了したときにテキストフィールドの値を取得できます。
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
NSString* myValue = myTextField.text; // get the value and do something
return YES;
}