ios - Sprite not staying on screen (left and right) -


i making game sprite moves around screen, have created collision edges using self.physicsbody = skphysicsbody(edgeloopfromrect: self.frame) seems work top , bottom of screen left , right sides sprite moves off screen. i'm not sure why is, appreciate advice beginner. included code scrolling background have set up. have other enemy sprites spawning off screen , moving view, maybe effects boundary?

class gamescene: skscene, skphysicscontactdelegate{  struct physicscategory {   static let none      : uint32 = 0   static let       : uint32 = uint32.max       static let edge   : uint32 = 0b1   static let spaceman: uint32 = 0b10   static let ship: uint32 = 0b11  }  override func didmovetoview(view: skview) {     /* setup scene here */        self.physicsbody = skphysicsbody(edgeloopfromrect: self.frame)     self.physicsbody?.categorybitmask = physicscategory.edge     physicsworld.contactdelegate = self       // repeating background     var bgtexture = sktexture(imagenamed: "spacebackground")     var movebg = skaction.movebyx(-bgtexture.size().width, y: 0, duration: 9)     var replacebg = skaction.movebyx(bgtexture.size().width, y: 0, duration: 0)     var moveforever = skaction.repeatactionforever(skaction.sequence([movebg, replacebg]))     var i:cgfloat=0; i<3; i++ {          var wave = skspritenode(texture: bgtexture)         wave.position = cgpoint(x: bgtexture.size().width/2 + bgtexture.size().width * i, y: cgrectgetmidy(self.frame))         wave.size.height = self.frame.height          wave.runaction(moveforever)          self.addchild(wave)      }       spaceman.texture = (texture1)     spaceman.position = cgpoint(x: self.frame.size.width/2, y: self.frame.size.height/2)    spaceman.setscale(0.4)        spaceman.physicsbody=skphysicsbody(rectangleofsize: thebat.size)     spaceman.physicsbody?.affectedbygravity = true     spaceman.physicsbody?.dynamic = true     spaceman.physicsbody?.allowsrotation = false     spaceman.physicsbody?.categorybitmask = physicscategory.spaceman     spaceman.physicsbody?.contacttestbitmask = physicscategory.ship     spaceman.physicsbody!.collisionbitmask = physicscategory.edge      self.addchild(spaceman) 

check make sure sceneview set bounds of viewcontroller, should done adding scene view, should 1 of these

/* set scale mode scale fit window */     scene.size = skview.bounds.size     scene.scalemode = .scaletofit;  /* set scale mode scale fit window */     scene.size = skview.bounds.size     scene.scalemode = .aspectfit; 

if .aspectfill, go outside screen bounds.

also showphysics = true in skview display collision bounds are.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -