zoukankan      html  css  js  c++  java
  • SpriteKit初探

    1.新建一个空项目,Devices选择iPhone,我用的Xcode 5的版本没有iPad模拟器。

    2.导入SpriteKit框架,依次新建两个类,ViewController : UIViewController,HelloWorldScene : SKScene。

    3.详细代码。

    AppDelegate.h中添加代码

    @property (strong,nonatomicUIViewController *viewController;

    AppDelegate.m中添加代码

    #import "ViewController.h"

     

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    {

        self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

        self.viewController = [[ViewController alloc]init];

        self.window.rootViewController =self.viewController;

        [self.window makeKeyAndVisible];

        return YES;

    }

     

    ViewController.h中添加代码

     

    #import <SpriteKit/SpriteKit.h>

    @property (strong,nonatomicSKView * skView;

    ViewController.m中添加代码

     

    #import "HelloWorldScene.h"

     

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        

        [self.view addSubview:self.skView];


       self.skView = [[SKView alloc]initWithFrame:self.view.bounds];

        [self.view addSubview:self.skView];

        self.skView.showsDrawCount =YES;

        self.skView.showsFPS =YES;

        self.skView.showsNodeCount =YES;

        

        SKScene * scene = [[HelloWorldScene alloc]initWithSize:self.skView.bounds.size];

        scene.scaleMode =SKSceneScaleModeAspectFill;

        

        [self.skView presentScene:scene];

    }

     

    HelloWorldScene.h中添加代码

     

    #import <SpriteKit/SpriteKit.h>

    HelloWorldScene.m中添加代码

    - (id)initWithSize:(CGSize)size{

       if(self = [super initWithSize:size]){

           SKLabelNode * label = [SKLabelNode labelNodeWithFontNamed:@"Avenir"];

            label.text =@"Hello World!";

            label.fontColor = [UIColor redColor];

            label.fontSize =20;

            label.position =CGPointMake(size.width/2, size.height/2);

            

            [self addChild:label];

        }

        return self;

    }

    4.类图。



  • 相关阅读:
    mysql密码忘记如何恢复(windows/liunx版本:mysql8.0.27)
    Visual Studio Code如何校验yaml格式文件
    python测试小工具
    Lunx vimgo 开发环境搭建
    小白学正则表达式之 regexp
    kubernetes scc 故障排查小记
    Go image registry
    OpenShift image registry 概述
    Go 疑难杂症汇总
    小白学标准库之 http
  • 原文地址:https://www.cnblogs.com/pingyunlong/p/3238751.html
Copyright © 2011-2022 走看看