-1

as the title suggests i have added a UITextView to my scene and it works fine. the only issue i have is when i use the back button to go back to the main menu the text view remains on the screen. for the life of me i can't figure out how to prevent this text view from remaining on the screen if the back button is pressed. can someone help me out please. the following is my the code i use in my SKScene:

@implementation HowToPlay


-(void)didMoveToView:(SKView *)view {

SKSpriteNode *bgImage = [SKSpriteNode spriteNodeWithImageNamed:@"vortex1.jpg"];
bgImage.size = self.frame.size;
bgImage.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:bgImage];

SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Thonburi-Bold"];
myLabel.text = @"Title";
myLabel.fontSize = 20;
myLabel.fontColor = [UIColor whiteColor];
myLabel.position = CGPointMake(275,290);
[self addChild:myLabel];

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(150, 40, 300, 240)];
textView.backgroundColor = [ UIColor  clearColor];
textView.text = @"this is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.\n\nthis is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.\n\nthis is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.";
textView.font = [UIFont fontWithName:@"Helvetica" size:20];
textView.textColor = [UIColor whiteColor];
[self.view addSubview:textView];

[self addChild: [self backButton]];
}
- (SKSpriteNode *)backButton
{
SKSpriteNode *button = [SKSpriteNode spriteNodeWithImageNamed:@"Back.png"];
[button setScale:0.5];
button.position = CGPointMake(50, 50);
button.name = @"Back";
return button;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

if ([node.name isEqualToString:@"Back"]) {
    [self runButtonActionOnNodeBack:node];
}
}

-(void)runButtonActionOnNodeBack:(SKNode*) node{
node.name = nil;
//SKAction *moveUp = [SKAction moveByX: 0 y: 100.0 duration: 0.5];
SKAction *zoom = [SKAction scaleTo: 0.8 duration: 0.25];
// *spin = [SKAction rotateToAngle:360.0f duration:1.0];
SKAction *pause = [SKAction waitForDuration: 0.5];
SKAction *fadeAway = [SKAction fadeOutWithDuration: 0.25];
SKAction *remove = [SKAction removeFromParent];
SKAction *moveSequence = [SKAction sequence:@[zoom, pause, fadeAway, remove]];
[node runAction: moveSequence completion:^{
    SKScene *mainMenu  = [[GameScene alloc] initWithSize:self.size];
    SKTransition *doors = [SKTransition doorsOpenHorizontalWithDuration:0.5];
    [self.view presentScene:mainMenu transition:doors];
}];
}
@end
Adrian P
  • 6,479
  • 4
  • 38
  • 55
  • Now why would any down vote this question and not comment why? That's unethical. I don't mind the don vote, I just like to know why. – Adrian P May 06 '15 at 22:32

1 Answers1

2

Save a reference to that text view and then remove it from it's superview when you want to get rid of it:

@interface HowToPlay()
@property (nonatomic, strong) UITextView *textView;
@end

@implementation HowToPlay

- (void)didMoveToView:(SKView *)view {
    self.textView = [[UITextView alloc]......
}

//whenever you want to open the menu/remove the text view:
[self.textView removeFromSuperview];
Aviel Gross
  • 9,770
  • 3
  • 52
  • 62
  • well done man. thanks a lot. i can't believe i didn't get that. i guess spending too much time trying to design games and i completely forgot about uikit. once again thanks a million for the answer and +1 too brother. – Adrian P May 06 '15 at 20:38
  • Its only embarrassing when you find yourself searching some problem on SO and realizing that you already up-voted the answer to that issue at some point... (: – Aviel Gross May 06 '15 at 20:40
  • Did I do that? I don't think I did, but non the less it is embarrassing anyway. – Adrian P May 06 '15 at 20:47