xcode - How can I make SKSpriteNode positions the same for any simulator/device? -
in game, position of sknodes change when run app on virtual simulator vs on real device(my ipad).
here pictures of talking about.
it hard see, 2 red boxes higher on ipad in simulator
here how declare size , position of red boxes , green net: following code located in gamescene.swift file
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) }
additionally gameviewcontroller.swift looks this
import uikit import spritekit class gameviewcontroller: uiviewcontroller { var scene: gamescene! override func viewdidload() { super.viewdidload() //configure view let skview = view as! skview //if finger on iphone, cant tap again skview.multipletouchenabled = false //create , configure 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 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 cached data, images, etc aren't in use. } override func prefersstatusbarhidden() -> bool { return true } }
how can make positions of nodes same each simulator/physical device?
you should round floating point values integers via call (int)round(float) values snap whole pixels. place use cgpoint or cgsize should use whole pixels opposed floating point values.