我正在尝试在SceneKit中绘制一个SpriteKit按钮。
似乎一切正常,但对象离开了屏幕。
代码:
import UIKit
import QuartzCore
import SceneKit
import SpriteKit
class GameViewController: UIViewController , SCNSceneRendererDelegate {
var walkAnimButton: SKSpriteNode!
var overlay: SKScene!
override func viewDidLoad() {
super.viewDidLoad()
...
self.setupHUD()
}
func setupHUD () {
let screenSize: CGSize = UIScreen.main.bounds.size
let sceneView = self.view as! SCNView
/* Create overlay SKScene for 3D scene */
overlay = SKScene.init(size: sceneView.bounds.size)
overlay.scaleMode = SKSceneScaleMode.aspectFill
sceneView.overlaySKScene = overlay
/* Create button for controlling walk animation */
let walkAnimButton: SKSpriteNode = SKSpriteNode.init(imageNamed: "walking")
walkAnimButton.anchorPoint = CGPoint(x: 0.5, y: 0.5)
walkAnimButton.size = CGSize(width: 32, height: 32)
walkAnimButton.position = CGPoint(x: screenSize.width-walkAnimButton.size.width, y: screenSize.height-walkAnimButton.size.height)
walkAnimButton.name = "WalkAnimationButton"
overlay.addChild(walkAnimButton)
}
}
可能是什么错误?
overlay.scaleMode = SKSceneScaleMode.aspectFill
提前致谢。