0

I'm trying to ask the user to input their name in a SKScene but whenever I add a subview it messes up the SKScene and it starts to replay the music and doesnt add the new SKScene that I have the textfield in. Here is my attempt.

-(void)didMoveToView:(SKView *)view{
    self.backgroundColor = [SKColor lightGrayColor]; // NOTE: temporary background color se
    UILabel *nameField = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 300, 100)];
    [self.view addSubview:nameField];
    //[self createMenuTxt];
    [self SetBrickBackground];
}

EDIT: I found a related post: Adding UITextView to a scene in SpriteKit

Which says that the reason is because the skScene is being presented everytime I add a UITextview. He said to use a guard: if(self.view.scene == nil){}, however, I'm getting that scene is not a property of UIView. Am I missing something?

Community
  • 1
  • 1
AzureWorld
  • 311
  • 2
  • 10

1 Answers1

0

In this case self is the view. So in effect you are saying self.self which obviously does not work.

Change the line [self.view addSubview:nameField]; to this [view addSubview:nameField];

sangony
  • 11,636
  • 4
  • 39
  • 55