关于为什么我的精灵没有以正确的顺序出现在这里的任何想法?雪花出现在索引0而不是1.
即使我改变了顺序,雪花仍然会出现在其他所有东西后面。
import Foundation
import SpriteKit
class page1: SKScene {
let background = SKSpriteNode(imageNamed: "01_BG")
let snowflake = SKSpriteNode(imageNamed: "home_snowflake02")
let room = SKSpriteNode(imageNamed: "01_room")
let kid = SKSpriteNode(imageNamed: "01_kidStanding")
override init(size: CGSize){
super.init(size: size)
}
override func didMoveToView(view: SKView) {
//Set up background
background.position = CGPoint(x: 200, y: 380)
background.xScale = 1.0
background.yScale = 1.0
insertChild(background, atIndex: 0)
//Set up Snowflakes
snowflake.position = CGPoint(x: 250, y: 1100)
snowflake.xScale = 1.0
snowflake.yScale = 1.0
insertChild(snowflake, atIndex: 1)
//Set up room
room.position = CGPoint(x: 512, y: 384)
room.xScale = 1.0
room.yScale = 1.0
insertChild(room, atIndex: 2)
//Set up kid
kid.position = CGPoint(x: 320, y: 290)
kid.xScale = 1.0
kid.yScale = 1.0
insertChild(kid, atIndex: 3)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
答案 0 :(得分:0)
如果您的场景视图将ignoresSiblingOrder属性设置为true,则可以提高性能,但兄弟精灵的顺序不可靠。
您可以直接设置精灵zPosition来处理此问题。
例如:
background.zPosition = 0
snowflake.zPosition = 1
或
snowflake.zPosition = background.zPosition + 1
保持相对于兄弟姐妹。