Integrating a SpriteKit view into a xib view

强颜欢笑 提交于 2019-11-30 21:24:20
lionserdar

I don't know what exactly you are trying to achieve but I think instead of SpriteKit you may wanna check out the UIKitDynamics which provides "physics-related capabilities and animations to views and other dynamic items". I would suggest you look at the apple doc first https://developer.apple.com/library/ios/samplecode/DynamicsCatalog/Introduction/Intro.html then a really nice tutorial on raywenderlich.com http://www.raywenderlich.com/50197/uikit-dynamics-tutorial

Hope this helps...

I just gave this a try, and worked.

  1. Started with single view app.
  2. Dragged in myScene.m / .h from another sprite kit app into my project.
  3. In storyboard dragged in a UIView, and set class to SKView in storyboard.
  4. Created an outlet from that to the VC class (in my case called it myGame)
  5. Added the #import in the VC class
  6. Also copied from the demo project viewDidLoad

This is the only change i made

-(void)viewDidLoad {
   [super viewDidLoad];
   // Next line is all I changed...
   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];
}

I added in some other UIKit to kind show how its a little SK Game in a view.

Not sure if this is the best way but I hope I answers your question.

I agree with lionserdar, and you should check out UIKit Dynamics instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!