skphysicsbody

Giving physics to tiles of SKTileMapNode in Xcode 8

半腔热情 提交于 2019-12-03 08:21:23
I am learning Swift, and as a project I am working on a tile based 2D game similar to super mario where my character will walk and jump on tiles. The latest version of Xcode and Sprite Kit give the ability to create a Tile Map directly in Xcode. In the presentation of the new Xcode and Sprite kit, the guy demonstrates a game similar to what i am working on. https://developer.apple.com/videos/play/wwdc2016/610/ (around the 20th minute). He mentions giving Tiles user data properties which i did, and in code we search through all the tiles which have that user data and give them some physics

Sprite Kit - Determine vector of swipe gesture to flick sprite

本秂侑毒 提交于 2019-12-03 06:23:27
问题 I have a game where circular objects shoot up from the bottom of the screen and I would like to be able to swipe them to flick them in the direction of my swipe. My issue is, I don't know how to calculate the vector/direction of the swipe in order to get the circular object to get flicked in the proper direction with the proper velocity. The static vector "(5,5)" I am using needs to be calculated by the swipe speed and direction of the swipe. Also, I need to make sure that once I make first

Sprite Kit - Determine vector of swipe gesture to flick sprite

房东的猫 提交于 2019-12-02 19:48:44
I have a game where circular objects shoot up from the bottom of the screen and I would like to be able to swipe them to flick them in the direction of my swipe. My issue is, I don't know how to calculate the vector/direction of the swipe in order to get the circular object to get flicked in the proper direction with the proper velocity. The static vector "(5,5)" I am using needs to be calculated by the swipe speed and direction of the swipe. Also, I need to make sure that once I make first contact with the object, it no longer happens, as to refrain from double hitting the object. Here's what

node.physicsBody.joints downcasting error

大兔子大兔子 提交于 2019-12-02 13:03:23
问题 The following code gives an error - it appears the physics joints array have the class PKPhysicsJoint. Anyone have any ideas how I can iterate through the joints in Swift? The documentation does say that physicsBody.joints should return an array of SKPhysicsJoint. import SpriteKit let scene = SKScene(size: CGSize(width: 200, height: 200)) let nodeA = SKNode() let nodeB = SKNode() nodeA.physicsBody = SKPhysicsBody(circleOfRadius: 20) nodeB.physicsBody = SKPhysicsBody(circleOfRadius: 20) scene

contacts not recognized when body is changed from circle to rectangle

寵の児 提交于 2019-12-02 07:33:24
With help from here I have made a circle body traverse a given path. I have some bodies at some of the path points and have logged contact in didBeginContact . When the body gets in contact with a specific body the circle body is changed to a rectangle. This rectangular body is suppose to traverse the same path as the original circle body but it doesn't reach the path points as the contact is not logged. I tried changing radiusPoint to the width or height of the rectangle also but that didn't work. Also the rectangle body is bigger than the circle body. How can I get the rectangle to traverse

How do I correctly use allContactedBodies?

╄→гoц情女王★ 提交于 2019-12-02 03:27:21
问题 I want to use allContactedBodies instead of didBeginContact & didEndContact. When I do : NSLog(@"%@", node.physicsBody.allContactedBodies ); And the correct contact happens with the object,I get something like: "<SKPhysicsBody> type:<Rectangle> representedObject:[<SKNode> name:'theBall' position:{149.55787658691406, 91.00054931640625} accumulatedFrame:{{70.462608337402344, -16.016334533691406}, {112.56977081298828, 127.18753814697266}}]" Now all I want to do is to say ok great, if you see the

node.physicsBody.joints downcasting error

前提是你 提交于 2019-12-02 02:50:44
The following code gives an error - it appears the physics joints array have the class PKPhysicsJoint. Anyone have any ideas how I can iterate through the joints in Swift? The documentation does say that physicsBody.joints should return an array of SKPhysicsJoint. import SpriteKit let scene = SKScene(size: CGSize(width: 200, height: 200)) let nodeA = SKNode() let nodeB = SKNode() nodeA.physicsBody = SKPhysicsBody(circleOfRadius: 20) nodeB.physicsBody = SKPhysicsBody(circleOfRadius: 20) scene.addChild(nodeA) scene.addChild(nodeB) let joint = SKPhysicsJointFixed.jointWithBodyA(nodeA.physicsBody,

How do I correctly use allContactedBodies?

删除回忆录丶 提交于 2019-12-02 01:31:19
I want to use allContactedBodies instead of didBeginContact & didEndContact. When I do : NSLog(@"%@", node.physicsBody.allContactedBodies ); And the correct contact happens with the object,I get something like: "<SKPhysicsBody> type:<Rectangle> representedObject:[<SKNode> name:'theBall' position:{149.55787658691406, 91.00054931640625} accumulatedFrame:{{70.462608337402344, -16.016334533691406}, {112.56977081298828, 127.18753814697266}}]" Now all I want to do is to say ok great, if you see the name:'theBall' then we are connected. So I tried to do the following code which doesn't work. if (

How to detect contact on different areas of a physicsbody

南楼画角 提交于 2019-12-02 01:14:50
I would like to achieve the classic 'headshot' effect in a sprite-kit game. My ideas and attempts: Create separate 'body' and 'head' physicsBodies on the same sprite and pin them with a joint. Impossible :( Create a 'body' physics body on the "enemy" sprite and create another transparent sprite with a 'head' physicsBody that follows the body (sits on top). This approach requires me to keep track of what head is associated with what body. It will also decrease the games efficiency. I am curious if I could make a subclass of SKSpriteNode and create an "enemy" that has these two spritenodes and

How to get SKSpriteNode by physicsBody?

▼魔方 西西 提交于 2019-12-01 12:18:19
I extended SKSpriteNode with my own class to have more functions. But how can I get this extended node when something 'hits' this node and didBeginContact is called? Because contact.bodyA and contact.bodyB are physicsBody and parent of this is the game scene. This is my subclass of SKSpriteNode: class Orange: SKSpriteNode { ... func createPhysicsBody(){ self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width / 2) self.physicsBody?.dynamic = true ... } } This is my didBeginContact code: func didBeginContact(contact: SKPhysicsContact){ switch(contact.bodyA.categoryBitMask + contact