SKSpriteNode 未加载到屏幕上?
Posted
技术标签:
【中文标题】SKSpriteNode 未加载到屏幕上?【英文标题】:SKSpriteNode Not Loading Onto Screen? 【发布时间】:2016-02-17 23:03:12 【问题描述】:一切正常,但是当我添加苹果时,它只会在屏幕上停留很短的时间,然后消失/消失。为什么是这样?任何帮助将不胜感激。
import SpriteKit
class GameScene: SKScene
var bg=SKSpriteNode()
var apple=SKSpriteNode()
override func didMoveToView(view: SKView)
/* Setup your scene here */
let bg_texture=SKTexture(imageNamed: "wood-texture-pattern.jpg")
bg=SKSpriteNode(texture: bg_texture)
bg.position=CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
bg.size.height=self.frame.height
bg.size.width=self.frame.width
self.addChild(bg)
let applePic=SKTexture(imageNamed:"apple.png")
apple=SKSpriteNode(texture:applePic)
apple.position=CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame))
// apple.size.height=50
// apple.size.width=50
apple.setScale(0.25)
self.addChild(apple)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
/* Called when a touch begins */
override func update(currentTime: CFTimeInterval)
/* Called before each frame is rendered */
【问题讨论】:
【参考方案1】:改变skspritenode的zPosition
【讨论】:
你可以通过 .zPosition 来做到这一点。较大的 zPosition 将导致在前面分层以上是关于SKSpriteNode 未加载到屏幕上?的主要内容,如果未能解决你的问题,请参考以下文章