问题
I have a view that I already created using a xib file.
Now I would like to add some small elements to this view that would make use some of the physics animations from SpriteKit, so now I need an SKView.
Is it possible to add an SKView as a Subview of the view that corresponds to my xib view? I tried this and it does not seem to show anything.
The following is in the ViewController corresponding to my XIB view:
this.myCustomSKView = new CustomSKView()
this.View.AddSubview( this.myCustomSKView );
and the ViewController for my custom SKView has:
public override void ViewWillLayoutSubviews ()
{
base.ViewWillLayoutSubviews ();
if(this.SKView.Scene == null)
{
this.SKView.ShowsFPS = true;
this.SKView.ShowsNodeCount = true;
this.SKView.ShowsDrawCount = true;
var scene = new MyCustomSKScene (this.SKView.Bounds.Size);
this.SKView.PresentScene (scene);
}
}
回答1:
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...
回答2:
I just gave this a try, and worked.
- Started with single view app.
- Dragged in myScene.m / .h from another sprite kit app into my project.
- In storyboard dragged in a UIView, and set class to SKView in storyboard.
- Created an outlet from that to the VC class (in my case called it myGame)
- Added the #import in the VC class
- 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.
来源:https://stackoverflow.com/questions/19258567/integrating-a-spritekit-view-into-a-xib-view