skphysicscontact

SKPhysicsContact Not Detecting categoryBitMask Collision

别等时光非礼了梦想. 提交于 2019-12-22 18:05:23
问题 So I have my "Floor.swift" class below which is basically a bunch of walls. I have objects coming from the top of the screen and once the Floor and SKSpriteNodes collide, I'd like the SKSpriteNode to be removed. Below is my Floor class. import Foundation import SpriteKit class Floor: SKNode { override init() { super.init() let leftWall = SKSpriteNode(color: UIColor.brown, size: CGSize(width: 5, height: 50)) leftWall.position = CGPoint(x: 0, y: 50) leftWall.physicsBody = SKPhysicsBody

didBeginContact passed PKPhyicsObject

前提是你 提交于 2019-12-21 17:18:37
问题 I have a helper method which extends SKPhysicsContact extension SKPhysicsContact { /// - returns: `[SKPhysicsBody]` containing all the bodies that match `mask` func bodiesMatchingCategory(mask: UInt32) -> [SKPhysicsBody] { let bodies = [bodyA, bodyB] return bodies.filter { ($0.categoryBitMask & mask) != 0 } } } in didBeginContact() I call this method on the passed in contact . func didBeginContact(contact: SKPhysicsContact) { let ballMask: UInt32 = 0x1 << 2 let ball = contact

App crashes on iPhone 4s but no other device: possible issue with SKPhysicsContactDelegate?

自古美人都是妖i 提交于 2019-12-11 08:27:32
问题 I've ran my spritekit game on the following devices: iPhone 5s, iPhone 4s, iPad air and iPad mini. The app runs and all the devices except the 4s. On the 4s the app crashes when the app transitions to scenes that include SKPhysicsContactDelegate, for example: class PlayScene: SKScene, SKPhysicsContactDelegate, ADBannerViewDelegate { enum ColliderType: UInt32 { case narrowCategory = 1 case bigCategory = 2 case smallCategory = 4 case roundCategory = 8 } var narrow = SKSpriteNode(imageNamed:

SKPhysicsContact Not Detecting categoryBitMask Collision

杀马特。学长 韩版系。学妹 提交于 2019-12-06 05:45:43
So I have my "Floor.swift" class below which is basically a bunch of walls. I have objects coming from the top of the screen and once the Floor and SKSpriteNodes collide, I'd like the SKSpriteNode to be removed. Below is my Floor class. import Foundation import SpriteKit class Floor: SKNode { override init() { super.init() let leftWall = SKSpriteNode(color: UIColor.brown, size: CGSize(width: 5, height: 50)) leftWall.position = CGPoint(x: 0, y: 50) leftWall.physicsBody = SKPhysicsBody(rectangleOf: leftWall.size) leftWall.physicsBody!.isDynamic = false self.addChild(leftWall) let rightWall =

didBeginContact passed PKPhyicsObject

旧巷老猫 提交于 2019-12-04 08:20:51
I have a helper method which extends SKPhysicsContact extension SKPhysicsContact { /// - returns: `[SKPhysicsBody]` containing all the bodies that match `mask` func bodiesMatchingCategory(mask: UInt32) -> [SKPhysicsBody] { let bodies = [bodyA, bodyB] return bodies.filter { ($0.categoryBitMask & mask) != 0 } } } in didBeginContact() I call this method on the passed in contact . func didBeginContact(contact: SKPhysicsContact) { let ballMask: UInt32 = 0x1 << 2 let ball = contact.bodiesMatchingCategory(ballMask) ... I get this error message sometimes (like 1 in 5) which crashes the app: -

beginner swift sprite kit - node collision detection help (SKPhysicsContact)

拟墨画扇 提交于 2019-11-28 14:25:35
I want a sprite to delete itself when touching another sprite. Right now when they touch, they just push each other. I have this: let alphaCategory: UInt32 = 0x1 << 0 let betaCategory: UInt32 = 0x1 << 1 I made the sprites dynamic and not affected by gravity self.physicsworld.contactDelegate = self alpha.physicsBody?.categoryBitMask = alphaCategory alpha.physicsBody?.contactTestBitmask = betaCategory and beta.physicsBody?.categoryBitMask = betaCategory beta.physicsBody?.contactTestBitmask = alphaCategory I couldn't find anything in swift that made sense to me, but I think the problem is here

beginner swift sprite kit - node collision detection help (SKPhysicsContact)

五迷三道 提交于 2019-11-27 08:35:47
问题 I want a sprite to delete itself when touching another sprite. Right now when they touch, they just push each other. I have this: let alphaCategory: UInt32 = 0x1 << 0 let betaCategory: UInt32 = 0x1 << 1 I made the sprites dynamic and not affected by gravity self.physicsworld.contactDelegate = self alpha.physicsBody?.categoryBitMask = alphaCategory alpha.physicsBody?.contactTestBitmask = betaCategory and beta.physicsBody?.categoryBitMask = betaCategory beta.physicsBody?.contactTestBitmask =