Swift - SpriteKit CGPoint 对齐 [英] Swift - SpriteKit CGPoint Alignment
问题描述
我正在快速开展一个项目,我能够制作一个精灵.我正在尝试在许多不同的位置制作精灵.作为测试,我将游戏场景中的代码替换为:
I'm working on a project in swift and I am able to make a sprite. I am trying to make a sprite at a number of different locations. As a test I replaced the code in the game scene to be:
class GameScene: SKScene {
override func didMoveToView(view: SKView){
let wall = SKSpriteNode(imageNamed: "Wall")
wall.position = CGPoint(x: 289, y: 0)
}
}
我不明白的是这段代码在左下角做了一个精灵.正如预期的那样,在 y 方向上只有一半的精灵显示,但 x 方向似乎完全关闭.如果我尝试将 x 值设置为低于 289 的任何数字,它将不会出现.0,0 点真的是 289,0 还是我错过了什么?如果这有所不同,我正在为 iphone 6 编程.
What I do not understand is this code makes a sprite in the lower left corner. As expected in the y direction only half of the sprite shows, but the x direction seems completely off. If I try to set the x value to any number below 289 it will not appear. Is the 0,0 point really 289,0 or am I missing something? I am programming for iphone 6 if that makes a difference.
谢谢!
推荐答案
您的场景不一定与您的视图大小相同.您可以按如下方式检查场景的大小:
Your scene it is not necessarily the same size of your view. You can check the size of your scene as follow:
view.scene!.frame.size
view.scene!.frame.width
view.scene!.frame.height
view.scene!.frame.midX
view.scene!.frame.midY
这篇关于Swift - SpriteKit CGPoint 对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!