我在Scenekit场景上叠加了Spritekit背景和标签。 当我尝试在iPhone 5和iPhone 6模拟器上运行程序时,SpriteKit节点不会自动适应不同的设备。 如何解决这个问题?
class GameOverlay: SKScene {
override init(size: CGSize) {
super.init(size: size)
//Start Game
let gameStart = SKSpriteNode(imageNamed: "GameStart")
gameStart.anchorPoint = CGPoint(x:0.5,y:0.5)
gameStart.position = CGPointMake(-size.width / 2 + 400 , size.height / 2 - 200)
gameStart.size = CGSize(width: 356 / 2, height: 86 / 2)
gameStart.setScale(1.0)
gameStart.zPosition = 1
SKSceneScaleMode.ResizeFill
self.addChild(gameStart)
//Quit node
let quit = SKLabelNode(fontNamed: "AvenirNext-Bold")
self.anchorPoint = CGPointMake(0.5, 0.5)
self.scaleMode = .AspectFill
quit.text = "Quit"
quit.fontColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
quit.position = CGPointMake(-size.width / 2 + 580 , size.height / 2 - 360)
quit.name = "quit"
self.addChild(quit)
//BG
let bg = SKSpriteNode(imageNamed: "22")
bg.anchorPoint = CGPoint(x:0.5,y:0.5)
bg.position = CGPoint(x:0.0, y:0.0)
bg.zPosition = -1
SKSceneScaleMode.ResizeFill
self.addChild(bg)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
答案 0 :(得分:2)
书写
SKSceneScaleMode.ResizeFill
确实没有效果。
要调整场景大小,您必须写
self.scaleMode = .ResizeFill
此代码
self.scaleMode = .ResizeFill
不会缩放你的场景,只是调整它的大小。
要缩放场景(并自动显示其内容),您可以编写
self.scaleMode = .Fill