Adding SKSpriteNode to UIView

I am stuck something, maybe someone can help me. I am working on a fast iOS game (I am a beginner iOS developer). In StoryBoard, I added some buttons, some views, etc. I added a link (rectangle) in my controller, for example (using ctrl + drag):

@IBOutlet weak var mainBoardGame: UIView!

      

In my GameScene, I create some SKSpriteNodes like:

playerSprite = SKSpriteNode(imageNamed: "playerImg")
playerSprite.position = ....
playerSprite.size = CGSize(width:...,height: ...)
self.addChild(playerSprite)

      

My problem is that these SKSpriteNodes appear behind the rectangle (mainBoardGame) I created in my storyboard. I tried to add something like

playerSprite.zPosition = 100

      

but still the same.

I think it would be better to add my playerSprite directly to my mainBoardGame (because it will appear inside it), but I don't know how to handle the UIView and SKSpriteNodes. How can I add SKSpriteNodes to UIView? How do I handle the z-order between them?

Basic question: how to handle UIView and SKSpriteNode? Thank.

The reason I built it in a storyboard is because I put in some flaws in order to have well-rendered elements on each of the iPhone screen sizes.

Is there a way to do this in SpriteKit?

c.ts.

+3


source to share


1 answer


SpriteKit doesn't play well with subviews. SKScene wants to take its place entirely, so the game's high-performance 2D engine can handle the magic.



Why not just create your own playbar in your scene, and have a closing view that takes up constraints? It's harder to give a more specific answer without more detailed code examples.

+2


source







All Articles