SpriteNode/Shapes更改大小并返回GameScene(Swift SpriteKit)后消失 [英] SpriteNode/Shapes change size and disappear after returning to GameScene (Swift SpriteKit)

查看:62
本文介绍了SpriteNode/Shapes更改大小并返回GameScene(Swift SpriteKit)后消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在处理的问题的GIF: http://i.imgur.com/hiF5lyw.gifv

如您所见,主要的Player是一个SKSpriteNode,当您击中一个下落的块(即SKShapeNode)时,游戏会切换到GameOver场景.当您在GameOver场景中单击重新启动并返回到GameScene时,下落的方块消失,并且Player精灵的尺寸及其y位置也会更改.

所有代码都包含非常详细的注释,但是如果您有任何疑问,请随时提出.

由于我的Player画面的大小基于屏幕的大小,因此切换场景时可能与屏幕大小的变化有关.而且,奇怪的掉落的敌人不会出现几秒钟,但随后节点数急剧增加,并触发了另一个GameOver场景转换.

也许我必须使用GameViewController进行一些更改?

任何帮助将不胜感激,我已经为它工作了几个小时,但我似乎无法弄清其混乱的原因.

解决方案

如果在进行转换时无法更改节点的大小,则应使用

size:self.size 代替 fileNamed:nameOfYourScene .这对我有用.

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.

解决方案

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.

这篇关于SpriteNode/Shapes更改大小并返回GameScene(Swift SpriteKit)后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆