Swift SpriteKit SKSpriteNode的“有时"不露面 [英] Swift SpriteKit SKSpriteNode's "Sometimes" Don't Show Up

查看:183
本文介绍了Swift SpriteKit SKSpriteNode的“有时"不露面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift和SpriteKit制作一个iOS.但是,我在运行我的应用程序时遇到了异常情况.有时,屏幕上没有出现飞船SKSpriteNodes,有时没有出现项目符号的SKSpriteNodes,有时一切都很好显示(我在代码中的其他位置添加了项目符号).在所有情况下,我都不会在两次运行之间更改代码.我直接在此屏幕上启动应用程序,因此我在想,这可能与这些SKSpriteNodes没有足够的时间进行初始化有关.有什么想法吗?

I am making an iOS using Swift and SpriteKit. However I am experiencing irregularity in the running of my app. Sometimes the ship SKSpriteNodes doesn't appear on the screen, sometimes the bullet's SKSpriteNodes don't appear, sometimes everything shows up fine (I add the bullets elsewhere in the code). In all cases I am not making changes to the code between runs. I am starting the app on this screen directly so I'm thinking maybe it has something to do with these SKSpriteNodes not having enough time to initialize. Any ideas?

推荐答案

设置self.shipzPosition,使其位于背景节点的前面.这样的事情(我会在设置位置后执行此操作):

Set the zPosition of the self.ship so that it is in front of the background nodes. Something like this (I would do this after setting the position):

self.ship.zPosition = 1.0

例如,您还可以在zPosition中使用负片,将self.background放下.将zPosition视为图层(支持小数),数字越大,节点越接近图层堆栈的顶部".

You can also use negatives in the zPosition, for instance, to drop the self.background down. Think of zPosition as layers (with support for decimals), the higher the number, the closer to the "top" of the layer stack your node will be.

这篇关于Swift SpriteKit SKSpriteNode的“有时"不露面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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