SpriteNode/Shapes change size and disappear after

2019-09-16 14:37发布

问题:

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.