spritekit uiviewcontroller委托twitter

时间:2014-05-29 09:48:56

标签: twitter uiviewcontroller delegates sprite-kit

我一直在尝试将Twitter整合到我的spritekit游戏中,并且我已经阅读了网络上的每篇文章。

我知道我必须为此委托和使用视图控制器,但我尝试过的每个例子都略有不同,似乎对我不起作用并导致我处于困惑状态。

我拒绝放弃,但请求你的帮助。

使用基本spritekit代码,有人可以解释或告诉我如何在用户点击屏幕后使用twiiter代码(见下文)

推特代码

SLComposeViewController *tweetSheet = [SLComposeViewController
                                            composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"TestTweet from the Game !!"];
[self presentViewController:tweetSheet animated:YES completion:nil];

UIViewControlller.h

        #import <UIKit/UIKit.h>
        #import <SpriteKit/SpriteKit.h>

        @interface ViewController : UIViewController

        @end

UIViewControlller.m

        #import "ViewController.h"
        #import "MyScene.h"

        @implementation ViewController

        - (void)viewDidLoad
        {
            [super viewDidLoad];

            // Configure the view.
            SKView * skView = (SKView *)self.view;
            skView.showsFPS = YES;
            skView.showsNodeCount = YES;

            // Create and configure the scene.
            SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
            scene.scaleMode = SKSceneScaleModeAspectFill;

            // Present the scene.
            [skView presentScene:scene];
        }

        - (BOOL)shouldAutorotate
        {
            return YES;
        }

        - (NSUInteger)supportedInterfaceOrientations
        {
            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
                return UIInterfaceOrientationMaskAllButUpsideDown;
            } else {
                return UIInterfaceOrientationMaskAll;
            }
        }

        - (void)didReceiveMemoryWarning
        {
            [super didReceiveMemoryWarning];
            // Release any cached data, images, etc that aren't in use.
        }

        @end

MyScene.h

        #import <SpriteKit/SpriteKit.h>

        @interface MyScene : SKScene

        @end

MyScene.m

        #import "MyScene.h"

        @implementation MyScene

        -(id)initWithSize:(CGSize)size {    
            if (self = [super initWithSize:size]) {
                /* Setup your scene here */

                self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];

                SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];

                myLabel.text = @"Hello, World!";
                myLabel.fontSize = 30;
                myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
                                               CGRectGetMidY(self.frame));

                [self addChild:myLabel];
            }
            return self;
        }

        -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

                **Run twitter code**


        }

        -(void)update:(CFTimeInterval)currentTime {
            /* Called before each frame is rendered */
        }

        @end

0 个答案:

没有答案