skphysicsbody

Multiple Contacts Issue in SpriteKit Game

依然范特西╮ 提交于 2019-12-13 00:15:10
问题 In my game, I have a ball, walls and gaps between these walls. Ball and walls are SKSpriteNode, gap is SKNode. I use gap to count the score. I have the following code to handle the contacts and collisions. I checked plenty of documents and tutorials but cant find why there are multiple gap contacts happen when my ball contacts the gap. It prints "gap contact" for 6 times every time. Bodytypes definitions: enum BodyType:UInt32 { case ball = 1 case wall = 2 case gap = 4 } Ball: var ball =

Why won't this SKPhysicsJointPin keep these 2 sprites together?

半世苍凉 提交于 2019-12-12 21:19:37
问题 I clearly don't understand the SKPhysicsJoint very well, but there is so little info on the web yet, other than the Apple docs of course. What is wrong with the following code, which I would think should keep the head and neck permanently joined - my intention is that they act like 2 pieces of paper with a pin, so that they can rotate a bit, but not just totally come apart. When I run this code, they fall to the bottom of the SKScene they're in, hit the ground, then the head falls off the

SKPhysicsBody not as expected

杀马特。学长 韩版系。学妹 提交于 2019-12-12 14:18:00
问题 I have the following code to create a rectangular brick and a physics body associated with it. I expected the physics body to be a solid rectangle same size and position as that of the brick, but am getting a body which I think has a poition offset and perhaps also a size difference. Is there some issue with the coordinate systems I have missed? What is the right way to approach this? - (void)addBrick { SKShapeNode *brick = [[SKShapeNode alloc] init]; CGRect brickBoundary = CGRectMake(0.0, 0

Is there a way to create a concave physicsBody in SpriteKit?

末鹿安然 提交于 2019-12-12 09:58:11
问题 I have an object on scene and my hero should not go through it, but it should be able to go inside of it, like a boat into the bay, surrounded by the other element. I tried all kinds of physicsBody having it have body with rectangle, texture, with polygon from path, but to no avail. I was reading somewhere that it is not possible to have a concave physicsBody, but only convex. I really need it to be able to be concave. Does anyone know how to resolve this? 回答1: You can create a concave

Ellipse SKPhysicsBody

跟風遠走 提交于 2019-12-12 01:07:13
问题 Which SKPhysicsBody body type would I use to create an elliptical physicsBody? I know I could make a curve out of straight lines and just have it not be a real ellipse, but it seems like there must be some way to squish a circle or create one? 回答1: Create an elliptical CGPath and create a polygon body with that path: CGPathRef path = CGPathRef CGPathCreateWithEllipseInRect(someRect, nil); SKPhysicsBody* body = [SKPhysicsBody bodyWithPolygonFromPath:path]; It's possible though that the created

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

Sprite Kit - Shadow on multiple moving object affected impulse and Gravity

筅森魡賤 提交于 2019-12-11 19:49:03
问题 Base on my first question here which was answered by Theis Egeberg (The solution was explained more by Theis in the comment and worked like magic)I would need to also know the following: (This might have a simple answer but I will leave it it to Theis or anyone who can figure it out.) What if I have another object bouncing off the the already moving ball in Y axis witch as a different speed ? how do I change alpha of its shadow on the ball. To explain it nicer and make it more confusing, lets

SpriteKit: Using SKTextureAtlas causes incorrect Physics Body

核能气质少年 提交于 2019-12-11 13:23:41
问题 I am building my first sprite kit game, and recently read an article that said to use SKTextureAtlas to improve performance. So I migrated all my sprite images into organized .atlas folders and updated the code accordingly. However, now my sprites have weird physics bodies (mainly over-enlarged) . For instance, my player sprite has three states: Flying (flat), Flying Up and Flying Down. The three images are pretty similar, with slight variations (arms pointing flat, up, down) . Before

Could not create physics body - Swift

吃可爱长大的小学妹 提交于 2019-12-11 07:44:57
问题 I have a Swift file called ChainsawMaker.swift which I want to use to create chainsaws throughout my game. When I call instances of this and add it to my game, the chainsaws and it's physics body get added to the game perfectly - except for an error that pops up in the console: "Physics Body: Could not create physics body". Here is the code for ChainsawMaker.swift: import SpriteKit class ChainsawMaker: SKSpriteNode { func longChainsawCreator2 () -> SKSpriteNode { //LONG CHAINSAW let

How to set physics body for a sprite with rounded corners

可紊 提交于 2019-12-11 06:57:55
问题 I have created a SKShapeNode in the following way, let sprite = SKShapeNode(rect: CGRect(x: -20, y: -10, width: 40, height: 20), cornerRadius: 10) I also set a physics body like so, sprite.physicsBody = SKPhysicsBody(rectangleOf: sprite.frame.size) but I realized that the collisions and contacts weren't precise, so I changed showsPhysics to true and got the following. How can I make the physics body precise, even for the rounded corners? 回答1: From the documentation: Maybe the #4 is your case