I want to implement a Textfield to input your name on my SpriteKit Game, so I have something like this:
SKLabelNode* gameTitle = [SKLabelNode labelNodeWithFo
to remove it use the
[myTextField removeFromSuperView];
if you don't want to use the method didMoveToView that insert the textField at the scene presentation, you can use this method:
-(void)insertUI{
ttaAppDelegate *myDel = [[UIApplication sharedApplication] delegate];
UIViewController *vc = myDel.window.rootViewController;
self.textField= [[UITextField alloc] initWithFrame:CGRectMake(self.size.width/2, self.size.height/2+20, 200, 40)];
self.textField.center = self.view.center;
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.textColor = [UIColor blackColor];
self.textField.font = [UIFont systemFontOfSize:17.0];
self.textField.placeholder = @"Enter your name here";
self.textField.backgroundColor = [UIColor whiteColor];
self.textField.autocorrectionType = UITextAutocorrectionTypeYes;
self.textField.keyboardType = UIKeyboardTypeDefault;
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
self.textField.delegate = self;
self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.button addTarget:self action:@selector(saveScore:) forControlEvents:UIControlEventTouchDown];
[self.button setTitle:@"Save" forState:UIControlStateNormal];
self.button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[vc.view addSubview:self.textField];
[vc.view addSubview:self.button];
vc.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;
[vc requestInterstitialAdPresentation];
}
You can add objects that inherits UIView's inside the didMoveToView:(SKView *)view
function
Just add that function to your SKScene
and move your UITextField
inside:
-(void)didMoveToView:(SKView *)view {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(self.size.width/2, self.size.height/2+20, 200, 40)];
textField.center = self.view.center;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textColor = [UIColor blackColor];
textField.font = [UIFont systemFontOfSize:17.0];
textField.placeholder = @"Enter your name here";
textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeYes;
textField.keyboardType = UIKeyboardTypeDefault;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.delegate = self.delegate;
[self.view addSubview:textField];
}