skphysicsjoint

Create a raycast in spritekit

一个人想着一个人 提交于 2021-02-18 19:29:30
问题 I am building a game using Spritekit and am trying to build a raycast that will connect the player with the point where the player tapped. It will be like a rope that connects the player to the point where he or she tapped. For example if a player taps at the point x: 0, y: 0 then it will become a rope that connects both things with each other. With the time the rope will become shorter and the player will be dragged against it. The player does have a physicsbody. When the player releases the

How to rotate sprites around a joint

耗尽温柔 提交于 2020-02-11 14:04:51
问题 I need to make the arms and hands rotate around the center of the hook, as shown in the image below without them separating or changing their shape (no changes in the angles between arms and hands just rotation at A), as in the image below: I tried rotating the arms but this made them separate and change form. You can check out my code below: let hookCategoryName = "hook" let leftArmCategoryName = "leftArm" let rightArmCategoryName = "rightArm" let leftHandCategoryName = "leftHand" let

How to rotate sprites around a joint

若如初见. 提交于 2020-02-11 14:02:29
问题 I need to make the arms and hands rotate around the center of the hook, as shown in the image below without them separating or changing their shape (no changes in the angles between arms and hands just rotation at A), as in the image below: I tried rotating the arms but this made them separate and change form. You can check out my code below: let hookCategoryName = "hook" let leftArmCategoryName = "leftArm" let rightArmCategoryName = "rightArm" let leftHandCategoryName = "leftHand" 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 SKPhysicsJointFixed odd behaviour

青春壹個敷衍的年華 提交于 2019-12-22 10:51:52
问题 I am trying to connect together two SKNodes which both have equal size circular physics bodies. They are positioned so as to be touching each other, and I want them to be locked together. From the documentation, it sounds like I want a SKPhysicsJointFixed , and I have tried creating one with the anchor point being the midpoint between the two nodes - like this: let fixedJoint = SKPhysicsJointFixed.joint(withBodyA: atom1.physicsBody!, bodyB: atom2.physicsBody!, anchor:midPoint) but this causes

SKPhysicsJointFixed doesn't keep nodes together while moving one

*爱你&永不变心* 提交于 2019-12-12 18:09:16
问题 I've created 2 SKSpriteNodes, and connected them by a SKPhysicsJointFixed, to keep them stuck together. The problem is when I apply a SKAction.move(by:, duration:) to the first, it moves alone. why is that, and how can I move them together? I've searched a lot, but can't seem to find any new or useful information. Please help. Thanks in advance. Here's the code: import SpriteKit class myGame: SKScene { var node1: SKSpriteNode! var node2: SKSpriteNode! func createNode(_ position: CGPoint,

How To Make An Extending Chain

会有一股神秘感。 提交于 2019-12-11 19:55:46
问题 Okay, I have had a few questions floating around stackoverflow now, and most of them are related to this one question. I've been trying to get it myself, and I have a couple of times but the result is never quite what I expected. I am trying to develop a chain that my sprite can throw. So far what I have done is thrown the lead of the hook from the centre of the sprite outward. Once it travels 10 pixels away from the sprites position it generates another link in the chain. The chain is then

Scaling a pendulum made with SKSpriteNodes

社会主义新天地 提交于 2019-12-11 04:05:55
问题 I've got a working clock with a pendulum, but the swinging arm does not scale correctly. Here's what it looks like before scaling... And then, after scaling... The clock face scales down, and so does the swing arm (the green line), but it looks like it scales around it's center point not the fulcrum at the center of the face. I can fix that scaling by setting the swing's anchorPoint so it scales toward one end rather than the center... swing.anchorPoint = CGPointMake(0, 0.5); but doing that

SpriteKit joint: follow the body

…衆ロ難τιáo~ 提交于 2019-12-07 16:11:26
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 the same path that head was some time ago. I think for this game the Pin joint should be the answer,

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