无论屏幕大小如何,如何在正确的位置显示精灵

时间:2014-05-15 08:59:31

标签: ios iphone objective-c sprite-kit

我正在使用“Sprite Kit”,我在某个点上显示了一个节点。它在“4英寸屏幕”上看起来很棒,但它在“3.5英寸屏幕”上关闭,并且在iPad的iPhone模拟器上真的关闭了。我设置了这样的位置:

    myNode.position = CGPointMake(self.size.width/2, self.size.height - self.size.height/10);

所以,我认为无论大小如何都应该正确显示,但事实并非如此。我确信我只是做错了什么,我认为(并希望)应该有一个简单的解决方案。

1 个答案:

答案 0 :(得分:4)

如果要将其显示在左上角,

myNode.position = CGPoint(x: myNode.size.width * 0.5,
                          y: self.size.height - myNode.size.height * 0.5)

到左中角,

myNode.position = CGPoint(x: myNode.size.width * 0.5, 
                          y: (self.size.height - myNode.size.height) * 0.5);

到左下角,

myNode.position = CGPoint(x: myNode.size.width * 0.5,
                          y: myNode.size.height * 0.5);

到中间底部,

 myNode.position  = CGPoint(x: (self.size.width - myNode.size.width) * 0.5,
                            y: myNode.size.height * 0.5);

到右下角,

 myNode.position  = CGPoint(x: (self.size.width - myNode.size.width) * 0.5,
                            y: myNode.size.height * 0.5);

到右上角,

myNode.position  = CGPoint(x: self.size.width - myNode.size.width * 0.5,
                           y: (self.size.height - myNode.size.height) * 0.5);

在右上角,

myNode.position  = CGPoint(x: self.size.width  - myNode.size.width * 0.5,
                           y: self.size.height - myNode.size.height * 0.5);

到中间屏幕,

myNode.position = CGPoint(x: (self.size.width - myNode.size.width) * 0.5,
                          y: (self.size.height - myNode.size.height) * 0.5);