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
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];