skphysicsbody

SKPhysicsBody from Texture gives null on collision in Spritekit

别来无恙 提交于 2019-12-24 07:39:35
问题 I am creating a game where character jumps and collect points (SOME OBJECT). When you tap character perform some animation from atlas. When it touches the points, score is increased by 1. I am using SKTexture to create physicbody of the character. When my character touches the point it crashes and show me this error fatal error: unexpectedly found nil while unwrapping an Optional value //Code Cat = SKSpriteNode(imageNamed: "cat"); Cat.size = CGSize(width: 100, height: 100) Cat.position =

Sprite Kit Physics Assertion failed: (typeA == b2_dynamicBody || typeB == b2_dynamicBody)

喜你入骨 提交于 2019-12-24 01:57:42
问题 I am trying to make a game with fully IOS 7 features using SpriteKit including Physics. So when user tabs to the screen, I am throwing a ball through some other balls (which are not moving and I set dynamic=NO for these target balls). What I want to do is: Immadiately stop the ball (I am using resting=YES for this) Switching categoryBitMask and contactTestBit mask from throwing ball to target ball's category / contactBitMask Stopping dynamics for this ball. Everything is okay except one thing

Can't change SKPhysicsJointLimit maxLength after adding the joint to SKPhysicsWorld in Sprite Kit

谁说我不能喝 提交于 2019-12-23 15:42:53
问题 So, I've created a ring of SKSpriteNodes which are essentially rectangles that are joined together using pin joints. I'd like to suspend this ring inside of an SKShapeNode circle. I have connected each of the nodes to the SKShapeNode using SKPhysicsJointLimit's. This all works fine, and I get the effect that I'm looking for if I set the maxLength to the "right" number, which I determine subjectively. I've stored all of the limit joints inside of an Array, so I can get easy access, and I've

SpriteKit SKPhysicsBody collision in one direction like a door you can only go through but not back

我是研究僧i 提交于 2019-12-23 10:39:43
问题 In SpriteKit SKPhysicsBody is it possible to have an object you can pass through but not go back. The idea is their is no collision in one direction so you go through and not go back, like a trap door. 回答1: I'm not quite sure one way physics are possible, but you should be able to mess with a physics body's collision bit mask while the game is running to achieve a similar affect. So you have have your door in an open state, and when it detects the player is touching it*, it changes the bit

Not able to apply impulse to SKSpriteNode physics body

大城市里の小女人 提交于 2019-12-23 09:38:07
问题 I am new to xcode's sprite kit and I'm an trying to apply an impulse to a SKSpriteNode's physics body. Here is how I create the scene: self.backgroundColor = [SKColor colorWithRed:0 green:0 blue:0 alpha:1.0]; self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; self.physicsBody.friction = 0.0f; self.physicsWorld.gravity = CGVectorMake(0.0f, 0.0f); ballCategory = 1; wallCategory = 2; self.physicsBody.categoryBitMask = wallCategory; Here is how I create the player AND give it

Does a parent have its children's physicsBodies?

隐身守侯 提交于 2019-12-23 06:20:48
问题 I was wondering what the physicsBody of a parent would be if all I do is this: let combinedBodies = SKSpriteNode() addChild(combinedBodies) //Create its children like this as an example: let child = SKSpriteNode(color: UIColor.red, size: CGSize(width: 10, height: 20)) child.physicsBody = SKPhysicsBody(rectangleOf: child.size) child.physicsBody?.categoryBitMask = collisionType.child.rawValue combinedBodies.addChild(child) allBodies.append(child.physicsBody?) Would the physicsBody of

Add a property observer on an existing property in an iOS library class

社会主义新天地 提交于 2019-12-23 02:08:15
问题 In my SpriteKit game, I want to add a property observer on the fieldBitMask property for the SKPhysicsBody of my sprites. I want to be informed when the fieldBitMask property changes so that I can take some action. I overrode SKPhysicsBody but when I tried assigning the overridden class to a sprite node like a normal SKPhysicsBody object I got a bunch of errors. I also thought about making an extension for SKPhysicsBody, but Apple documentation says, “Extensions can add new functionality to a

Connect Physicsbodies on TileMap in SpriteKit

给你一囗甜甜゛ 提交于 2019-12-23 01:45:23
问题 I use the following function to append physicsbodies on tiles from a SKTileMapNode: static func addPhysicsBody(to tileMap: SKTileMapNode, and tileInfo: String){ let tileSize = tileMap.tileSize let halfWidth = CGFloat(tileMap.numberOfColumns) / 2 * tileSize.width let halfHeight = CGFloat(tileMap.numberOfRows) / 2 * tileSize.height for row in 0..<tileMap.numberOfColumns{ for column in 0..<tileMap.numberOfRows{ let tileDefinition = tileMap.tileDefinition(atColumn: column, row: row) let

SpriteKit joint: follow the body

有些话、适合烂在心里 提交于 2019-12-23 01:06:14
问题 I've been asked to simplify this question, so that's what I'm doing. I'm struggling in SpriteKit's physic joints (and possibly physic body properties). I tried every single subclass and many configurations but seams like nothing works or I'm doing something wrong. I'm developing Snake game. User controls head of snake which should move at constant speed ahead and user can turn it clockwise or anticlockwise. All the remaining snake's pieces should follow the head - they should travel exactly

SpriteKit Weird 'PKPhysicsBody' Crash

旧街凉风 提交于 2019-12-22 07:25:12
问题 I am trying to implement a simple category for SKPhysicsBody that will allow me to apply 'perfect bouncing' to a physics body. What this will simply do is when perfectBouncing = YES the following will happen: restitution = 1.0 linearDamping = 0.0 friction = 0.0 However, when I try to use my implementation as shown below, I get a weird crash telling me that I can't send perfectBouncing messages to PKPhysicsBody , which is a class that I never refer to and doesn't exist in my project or to my