testing - Contact Test Bit Mask not working proper -


contacttestbitmask works in general if graphic complex contacttestbitmask freaks out , have small contact area or weird errors. can there?

this image area:

enter image description here

class gamescene: skscene, skphysicscontactdelegate { let wallcategory   : uint32 = 0x1 << 1 let shipcategory : uint32 = 0x1 << 2 var counter = 0 var usercanbuild1building = false var kamerasichtvar:skcameranode = skcameranode()   var touched:bool = false var starttouch = cgpointmake(0, 0) //------------------------------   var draufgeklickt:cgpoint = cgpoint() var draufgeklicktupdate:cgpoint = cgpoint() var userwantscroll = false var userwantbuild = false let wohnhausblue = skspritenode(imagenamed:"wohnhausblue") let buildmenu = skspritenode(imagenamed:"buildmenu") var hitdetected = false    let actualbuilding = skspritenode() var userwantupgrade : bool = false //var thebuildingbefore = skspritenode() //var houselvlsave : int = 0 var uphaussave : string = "" func didbegincontact(contact: skphysicscontact) {      var buildingobject: skphysicsbody     var clickobject: skphysicsbody      if contact.bodya.categorybitmask < contact.bodyb.categorybitmask     {         buildingobject = contact.bodya         clickobject = contact.bodyb     }     else     {         buildingobject = contact.bodyb         clickobject = contact.bodya     }       // upgrade building     let name = buildingobject.node!.name     let houselvl: int = int(name!)!     if houselvl > 0 && usercanbuild1building == true{          usercanbuild1building = false         let touchedbuilding = skspritenode(imagenamed: buildingobject.node!.name!)         touchedbuilding.name = buildingobject.node!.name          let name = buildingobject.node!.name         var houselvl: int = int(name!)!         houselvl = houselvl + 1          let uphaus = string(houselvl)          let setspritetexture = skaction.settexture(sktexture(imagenamed: uphaus))         let upsize = skspritenode(imagenamed: uphaus)         let resizehousewidth = skaction.resizetowidth(upsize.size.width, duration: 0)         let resizehouseheight = skaction.resizetoheight(upsize.size.height, duration: 0)            touchedbuilding.runaction(resizehousewidth)         touchedbuilding.runaction(resizehouseheight)         touchedbuilding.runaction(setspritetexture)         touchedbuilding.name = "\(uphaus)"          touchedbuilding.position = buildingobject.node!.position         touchedbuilding.zposition = buildingobject.node!.zposition         touchedbuilding.userinteractionenabled = false          let upgradedbuilding = skspritenode(imagenamed: uphaus)         touchedbuilding.size = cgsizemake(upgradedbuilding.size.width, upgradedbuilding.size.height)         touchedbuilding.physicsbody = skphysicsbody(texture: sktexture(imagenamed:"\(uphaus)"), size: upgradedbuilding.size)           touchedbuilding.physicsbody?.categorybitmask = wallcategory         touchedbuilding.physicsbody?.affectedbygravity = false         touchedbuilding.physicsbody?.dynamic = true         touchedbuilding.physicsbody?.collisionbitmask = 0          addchild(touchedbuilding)         buildingobject.node?.removefromparent()         clickobject.node?.removefromparent()           }       if houselvl == 0     {     clickobject.node?.removefromparent()     }             }`override func didmovetoview(view: skview) {     /* setup scene here */      if let kamerasicht:skcameranode = self.childnodewithname("kamera") as? skcameranode{         kamerasichtvar = kamerasicht         self.camera = kamerasichtvar       }       physicsworld.contactdelegate = self     self.physicsworld.gravity = cgvectormake(0, 0)      func addbg(){          let background = skspritenode(imagenamed: "0")         background.name = "0"         background.anchorpoint = cgpointmake(0.5, 0.5)         background.zposition = 2         background.position = cgpointmake(cgrectgetminx(self.frame)+self.frame.width/4, cgrectgetmaxy(self.frame)-self.frame.height/4)         background.physicsbody = skphysicsbody(texture: sktexture(imagenamed: "0"), size: background.size)         //background.physicsbody = skphysicsbody(rectangleofsize: background.size)         background.physicsbody?.categorybitmask = wallcategory         background.physicsbody?.affectedbygravity = false         background.physicsbody?.dynamic = true         background.physicsbody?.collisionbitmask = 0           self.addchild(background)      }      addbg()       let wall = skspritenode(imagenamed:"1" )     wall.name = "1"     wall.zposition = 10     //wall.xscale = 3     //wall.yscale = 3     wall.size = cgsizemake(100, 100)     wall.position = cgpoint(x:cgrectgetmidx(self.frame), y:cgrectgetmidy(self.frame))     wall.physicsbody = skphysicsbody(texture: sktexture(imagenamed: wall.name!), size: wall.size)     //wall.physicsbody = skphysicsbody(rectangleofsize: wall.size)     wall.physicsbody?.affectedbygravity = false     wall.physicsbody?.dynamic = false     wall.physicsbody!.categorybitmask = wallcategory     wall.physicsbody?.collisionbitmask = 0     self.addchild(wall)     } 

`

ok found solution. problem weird behavior of contacttestbitmask when use graphic.(it detected contact in small area of graphic). reason graphic have separated shapes (like half ring , other small stuff).

i connected shape 1 shape , works fine. tried other graphics , behavior of contacttestbitmask is: if have separated shapes in graphic, contacttestbitmask take 1 of shapes , make contact area ...but other shapes in graphic not detect contact then...


Comments