在GameViewController中
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidLayoutSubviews() {
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
var boo = Bool();
boo = true;
skView.showsFPS = boo;
skView.showsNodeCount = boo;
skView.showsPhysics = boo;
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}在didMoveToView
var hero = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: 40, height: 40));
let hero_body = SKPhysicsBody(rectangleOfSize: hero.size);
hero.position = CGPoint(x:self.frame.size.width/2, y:50);
self.addChild(hero)我不明白这个职位是如何工作的。当Y为50时,矩形不显示。之前,在使用目标-c的xcode 5中,为了使节点位于屏幕底部,我将这样做。
-self.frame.size.height/2 + hero.size.height/2但在这里这不起作用
发布于 2014-10-18 18:20:04
这个评论是对的。-self.frame.size.height/2 + hero.size.height/2在锚点为CGPointMake(0.5f,0.5f);时工作,在您的情况下,锚点似乎从未从(0,0)更改过。要更改它,请在场景中使用self.anchorPoint = CGPointMake(0.5f, 0.5f);方法。
https://stackoverflow.com/questions/26420733
复制相似问题