SpriteNode/Shapes change size and disappear after returning to GameScene (Swift SpriteKit)

…衆ロ難τιáo~ 提交于 2019-12-25 04:50:16

问题


GIF of the issue in action: http://i.imgur.com/hiF5lyw.gifv

As you can see, the main Player is a SKSpriteNode, and when you hit a falling block which is a SKShapeNode, the game switches to the GameOver scene. When you click restart in the GameOver scene and move back to the GameScene the falling blocks disappear and the dimensions of the Player sprite is changed along with its y position.

All the code contains pretty detailed comments but if you have any questions about it feel free to ask.

Since the size of my Player sprite is based on the size of the screen, It might have something to do with screen size changes when switching scenes maybe. Also, its strange the falling block enemies dont show up for a few seconds, but then the node count drastically increases and another GameOver scene transition is triggered.

Maybe I have to change something with the GameViewController?

Any help would be greatly appreciated, I've been working at it for hours and I cant seem to figure out why its messing up.


回答1:


Figured it out. I created two new variables:

var transition:SKTransition = SKTransition.fadeWithDuration(0.5)

and

var gameOver:SKScene = GameOver(size: self.size)

And then implemented both when calling the scene switch with:

self.view?.presentScene(gameOver, transition: transition)

I think the size: self.size is what fixed it.




回答2:


If you have troubles with changing size of your nodes when you do transitions, instead of size: self.size, you should use fileNamed: nameOfYourScene. This worked for me.



来源:https://stackoverflow.com/questions/31442212/spritenode-shapes-change-size-and-disappear-after-returning-to-gamescene-swift

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