私のSKNodeの位置は、実際のデバイス(私のiPad)に対して仮想シミュレータを使ってアプリケーションを実行すると少し変化します。どのシミュレータ/デバイスでもSKSpriteNodeの位置を同じにすることはできますか?
ここに私が話していることの写真があります。
見えにくいですが、2つの赤いボックスはシミュレータここ
に比べて私のiPad上でわずかに高いです私はのサイズと位置を宣言する方法です赤いボックスと緑のネット: 次のコードは、私のGameScene.swiftファイルにあります。
func loadAppearance_Rim1() {
Rim1 = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake((frame.size.width)/40, (frame.size.width)/40))
Rim1.position = CGPointMake(((frame.size.width)/2.23), ((frame.size.height)/1.33))
Rim1.zPosition = 1
addChild(Rim1)
}
func loadAppearance_Rim2(){
Rim2 = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake((frame.size.width)/40, (frame.size.width)/40))
Rim2.position = CGPoint(x: ((frame.size.width)/1.8), y: ((frame.size.height)/1.33))
Rim2.zPosition = 1
addChild(Rim2)
}
func loadAppearance_RimNet(){
RimNet = SKSpriteNode(color: UIColor.greenColor(), size: CGSizeMake((frame.size.width)/7.5, (frame.size.width)/150))
RimNet.position = CGPointMake(frame.size.width/1.99, frame.size.height/1.33)
RimNet.zPosition = 1
addChild(RimNet)
}
func addBackground(){
//background
background = SKSpriteNode(imageNamed: "Background")
background.zPosition = 0
background.size = self.frame.size
background.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
self.addChild(background)
}
はまた私のGameViewController.swiftこの
import UIKit
import SpriteKit
class GameViewController: UIViewController {
var scene: GameScene!
override func viewDidLoad() {
super.viewDidLoad()
//Configure the view
let skView = view as! SKView
//If finger is on iphone, you cant tap again
skView.multipleTouchEnabled = false
//Create and configure the scene
//create scene within size of skview
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
scene.size = skView.bounds.size
//scene.anchorPoint = CGPointZero
//present the scene
skView.presentScene(scene)
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .Landscape
} else {
return .All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
ようになりますどのように私は、ノードの位置は、各シミュレータ/物理デバイスで同じにすることができますか?
@Darvydasこの質問は、このスタックオーバーフローポストで回答した場合と非常に似ています。 "http://stackoverflow.com/questions/33787770/how-to-scale-position-nodes-swift-spritekit-custom-view " 正しい方向に私を向けることができますか? –
この問題は、私がバックグラウンドを設定する方法と関係しているのでしょうか? –