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);
}
}
I just gave this a try, and worked.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With