gpt4 book ai didi

ios - Sprite Kit SKSpriteNode 绘制在屏幕外

转载 作者:行者123 更新时间:2023-11-28 05:34:58 24 4
gpt4 key购买 nike

GameScene.swift:

override func didMoveToView(view: SKView) {

self.backgroundColor = SKColor.whiteColor()

self.player = SKSpriteNode(imageNamed:"player")
self.player.position = CGPointMake(100, 100)
self.player.size = CGSize(width: self.player.size.width*2, height: self.player.size.height*2)
self.addChild(self.player)

}

GameViewController.swift:

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
skView.showsFPS = false
skView.showsNodeCount = false

/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true

/* Set the scale mode to scale to fit the window */
scene.size = skView.bounds.size
scene.scaleMode = .AspectFill;

skView.presentScene(scene)
}
}

在 iPhone 4S 上,播放器在屏幕上正确绘制
但是在iPhone 5/5s上运行,播放器被绘制在屏幕下方,只能看到一半的spritenode

iPhone 4S:

iPhone 5/5s:(注意:屏幕截图大小不同, Sprite 节点大小正确,但位置不对)

最佳答案

听起来这可能是您选择 SKSceneScaleMode 的问题,具体来说,听起来您可能选择了调整大小填充比例模式。将其更改为 SKSceneScaleModeAspectFill 应该足以解决此问题。

关于ios - Sprite Kit SKSpriteNode 绘制在屏幕外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24245086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com