skphysicsbody

iOS SpriteKit - collisions and contacts not working as expected [closed]

帅比萌擦擦* 提交于 2019-11-27 23:19:10
Sometimes in my SpriteKit programs, my collisions and contacts (using SKPhysicsBody) don't trigger or work as expected. I think I have set up everything I need, but I am still not getting the right interactions. How can I easily check what will collide with what and what bodies are set up to generate contacts? To help diagnose these types of problems, I have written a function that can be called from anywhere and which will analyse the current scene and produce a list of what nodes with collide with which others and which collisions my scene will be notified for. The function is stand-alone

SpriteKit SKPhysicsBody bodyWithTexture is Upside Down

丶灬走出姿态 提交于 2019-11-27 18:23:06
问题 Hi I'm trying to fix this bug with spritekit's physics shape appearing upside down. [SKPhysicsBody bodyWithTexture:monsterTexture size:monsterTexture.size] The first time the monster appears the phsyics body orientation is correct. But the second time and every time after that the monster appears it's physics body is inverted along the Y axis. See picture where skView.showsPhysics = true; so the physics shapes are displayed. The fact that it works correctly the first time makes me think maybe

How does collisionBitMask work? Swift/SpriteKit

南笙酒味 提交于 2019-11-27 18:11:38
As far as I'm aware the default for Physics bodies is to bounce off each other when they hit each other until you set their collisionBitMask to an equal number. However, I'm having a huge issue accomplishing what seems like it should be very simple because of collisionBitmasks I believe. let RedBallCategory : UInt32 = 0x1 << 1 let GreenBallCategory: UInt32 = 0x1 << 2 let RedBarCategory : UInt32 = 0x1 << 3 let GreenBarCategory : UInt32 = 0x1 << 4 let WallCategory : UInt32 = 0x1 << 5 greenBall.physicsBody?.categoryBitMask = GreenBallCategory greenBall.physicsBody?.contactTestBitMask =

SKPhysicsBody bodyWithPolygonFromPath memory leaks

别说谁变了你拦得住时间么 提交于 2019-11-27 06:02:32
问题 I have a strange memory leaks when creating Sprite Kit physics bodies with custom shapes. This is how my implementation looks: CGFloat offsetX = self.frame.size.width * self.anchorPoint.x; CGFloat offsetY = self.frame.size.height * self.anchorPoint.y; CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 4 - offsetX, 3 - offsetY); CGPathAddLineToPoint(path, NULL, 66 - offsetX, 3 - offsetY); CGPathAddLineToPoint(path, NULL, 35 - offsetX, 57 - offsetY); CGPathCloseSubpath

didBeginContact is being called multiple times for the same SKPhysicsBody

吃可爱长大的小学妹 提交于 2019-11-27 03:30:31
问题 func didBeginContact(contact: SKPhysicsContact) { if ( contact.bodyA.categoryBitMask & BodyType.shield.rawValue ) == BodyType.shield.rawValue { contact.bodyB.node?.removeFromParent() counter++ println(counter) } else if ( contact.bodyB.categoryBitMask & BodyType.shield.rawValue ) == BodyType.shield.rawValue { contact.bodyA.node?.removeFromParent() counter++ println(counter) } } One physics body is from a texture shield.physicsBody = SKPhysicsBody(texture: shieldTexture, size: shieldTexture

Physicsbody doesn't adhere to node's anchor point

有些话、适合烂在心里 提交于 2019-11-27 03:02:58
问题 My scene has a bunch of rectangles with physics bodies that are the same size as the rectangle. I like to anchor all of my objects to CGPointZero, however I've noticed when I do that the physicsbody remains anchored in the middle. In other words, the position of my physics body is like 100 pixels lower and to the left of the visual representation. Here is a simple snippet of code: SKSpriteNode* square = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(width, height)];

How to Detect collision in Swift, Sprite kit

╄→гoц情女王★ 提交于 2019-11-27 02:28:01
I was programming this simple space game in Swift until I encountered the problem of detecting collisions. After looking around forums, tutorials, etc, I tried to implement collisions by declaring bitmasks like so: object 1 enemy?.physicsBody = SKPhysicsBody(circleOfRadius: ((enemy?.size.width)!/2)) enemy?.physicsBody?.categoryBitMask = enemyBitMask enemy?.physicsBody?.contactTestBitMask = bulletBitMask enemy?.physicsBody?.collisionBitMask = 0 object 2 bullet?.physicsBody? = SKPhysicsBody(rectangleOf: (bullet?.size)!) bullet?.physicsBody?.categoryBitMask = bulletBitMask bullet?.physicsBody?

iOS SpriteKit - collisions and contacts not working as expected [closed]

痴心易碎 提交于 2019-11-26 21:24:48
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . Sometimes in my SpriteKit programs, my collisions and contacts (using SKPhysicsBody) don't trigger or work as expected. I think I have set up everything I need, but I am still not getting the right interactions. How can I easily check what will collide with what and what bodies are set up to

How does collisionBitMask work? Swift/SpriteKit

谁说胖子不能爱 提交于 2019-11-26 19:20:51
问题 As far as I'm aware the default for Physics bodies is to bounce off each other when they hit each other until you set their collisionBitMask to an equal number. However, I'm having a huge issue accomplishing what seems like it should be very simple because of collisionBitmasks I believe. let RedBallCategory : UInt32 = 0x1 << 1 let GreenBallCategory: UInt32 = 0x1 << 2 let RedBarCategory : UInt32 = 0x1 << 3 let GreenBarCategory : UInt32 = 0x1 << 4 let WallCategory : UInt32 = 0x1 << 5 greenBall

How to Detect collision in Swift, Sprite kit

醉酒当歌 提交于 2019-11-26 12:33:27
问题 I was programming this simple space game in Swift until I encountered the problem of detecting collisions. After looking around forums, tutorials, etc, I tried to implement collisions by declaring bitmasks like so: object 1 enemy?.physicsBody = SKPhysicsBody(circleOfRadius: ((enemy?.size.width)!/2)) enemy?.physicsBody?.categoryBitMask = enemyBitMask enemy?.physicsBody?.contactTestBitMask = bulletBitMask enemy?.physicsBody?.collisionBitMask = 0 object 2 bullet?.physicsBody? = SKPhysicsBody