've got a simple little game I'm playing with, not really for release but a learning tool for myself and SpriteKit.
I've got an app pulled together based loosely on this tutorial
http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
On my gameover scene that is presented once the user has lost the game I have placed a node with a desire to have the user be able to tap on it to bring up a Tweet sheet to be able to share something (perhaps a score or similar)
The code I have so far is reasonably straight forward:
I've tried various tutorials and guides to get this working but can't find anyway to present a modal view in an SKScene. Any help is greatly appreciated.
I've got an app pulled together based loosely on this tutorial
http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
On my gameover scene that is presented once the user has lost the game I have placed a node with a desire to have the user be able to tap on it to bring up a Tweet sheet to be able to share something (perhaps a score or similar)
The code I have so far is reasonably straight forward:
Code:
import "GameOverScene.h"
import "MyScene.h"
import
@implementation GameOverScene
-(id)initWithSize:(CGSize)size won:(BOOL)won { if (self = [super initWithSize:size]) {
// 1
self.backgroundColor = [SKColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
// 2
NSString * message;
if (won) {
message = @"You've killed 12,000,000 birds...now go out and see the sun again!";
} else {
NSInteger finalScore = [[NSUserDefaults standardUserDefaults] integerForKey:@"Result"];
NSString *messagetoshow = [NSString stringWithFormat:@"%d", finalScore];
NSString *finalmessage = [messagetoshow stringByAppendingString:@" Flappys eliminated..."];
message = finalmessage;
}
// 3
SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
label.text = message;
label.fontSize = 40;
label.fontColor = [SKColor blackColor];
label.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:label];
NSString * ShareTwitter;
ShareTwitter = @"Tweet all about it!";
SKLabelNode *tweetButton = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
tweetButton.text = ShareTwitter;
tweetButton.fontColor = [SKColor blueColor];
tweetButton.position = CGPointMake(self.size.width/2, 50);
tweetButton.name = @"tweet";
[self addChild:tweetButton];
// 4
[self runAction:
[SKAction sequence:@[
[SKAction waitForDuration:3.0],
[SKAction runBlock:^{
// 5
SKTransition *reveal = [SKTransition flipHorizontalWithDuration:0.5];
SKScene * myScene = [[MyScene alloc] initWithSize:self.size];
[self.view presentScene:myScene transition: reveal];
}]
]]
];
}
return self;
}
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:location]; //1
if ([node.name isEqualToString:@"tweet"]) {
//2
//Insert Tweet stuff here
}
}
@end
I've tried various tutorials and guides to get this working but can't find anyway to present a modal view in an SKScene. Any help is greatly appreciated.