skphysicsbody

How to make physics bodies stick to nodes anchor points

…衆ロ難τιáo~ 提交于 2019-12-17 20:29:54
问题 I have four squares in the middle of my scene set up with various anchor points. When tapped, they move together and come apart depending on what position: func rotate(angle : CGFloat, animated : Bool) { var rotateAction : SKAction! if animated { rotateAction = SKAction.rotateByAngle(angle, duration: 0.6) } else { rotateAction = SKAction.rotateByAngle(angle, duration: 0) } for node in self.children as! [SKSpriteNode] { node.runAction(rotateAction) } } } The problem I have is that that the

applyForce(0, 400) - SpriteKit inconsistency

一个人想着一个人 提交于 2019-12-17 18:19:07
问题 So I have an object that has a physicsBody and gravity affects it. It is also dynamic. Currently, when the users touches the screen, I run the code: applyForce(0, 400) The object moves up about 200 and then falls back down due to gravity. This only happens some of the time. Other times, it results in the object only moving 50ish units in the Y direction. I can't find a pattern... I put my project on dropbox so it can be opened if anyone is willing to look at it. https://www.dropbox.com/sh

Add boundaries to an SKScene

耗尽温柔 提交于 2019-12-14 04:20:33
问题 I'm trying to write a basic game using Apple's Sprite Kit framework. So far, I have a ship flying around the screen, using SKPhysicsBody. I want to keep the ship from flying off the screen, so I edited my update method to make the ship's velocity zero. This works most of the time, but every now and then, the ship will fly off the screen. Here's my update method. // const int X_MIN = 60; // const int X_MAX = 853; // const int Y_MAX = 660; // const int Y_MIN = 60; // const float SHIP_SPEED = 50

SpriteKit SKPhysicsBody with Inner Edges

和自甴很熟 提交于 2019-12-14 04:17:52
问题 I have created an SKSpriteNode called let's say Map that has an edge path that I have defined (some simple polygon shape). What I am trying to figure out is how to add several other edge paths that would act as interior edges of the Map . As if the "map" as a whole did in fact have holes . Some sort of inner boundary shapes that could act with Map as a whole: one edge path (as shown below) © I understand that there is a method that allows for creating an SKPhysicsBody with bodies (some

SKPhysicsBody Change Center of Mass

牧云@^-^@ 提交于 2019-12-14 01:29:54
问题 I am currently working on a game where I have a picture of a kind of cylindrical object, and I make an SKPhysicsBody with the following: self.oval.node.physicsBody = SKPhysicsBody(texture: self.oval.node.texture, size: self.oval.node.size) This method creates a nice shape around the node, however, the center of gravity is way off... It balances on the tip of the oval. Is there anyway to change that so it balances where the heaviest part should in theory be? Thanks! 回答1: The center of mass can

SpriteKit SKPhysicsBody broken collisions

有些话、适合烂在心里 提交于 2019-12-13 19:44:03
问题 I have a SKSpriteNode which has a static body, generated from concave path with edgeChainFromPath . Let's call this node a house . I also have another kind of SKSpriteNode s which have a dynamic square body, generated with rectangleOfSize . Let's call this node a box . In my scene, the boxes are thrown aka impulsed into the house and since both of them have bodies, the boxes should collide with the house and bounce away. I'm scrolling the scene and therefore creating new instances of EXACTLY

How to set bounds to Scene physics body to bounce properly?

那年仲夏 提交于 2019-12-13 18:51:28
问题 I implemented a simple physics to bounce a sprite node , and everything worked except the node is bouncing off the screen for the top and bottom.It is fine for the sides, but it goes off the screen for top and bottom view. Here is the view: As you can see, I the ball is going off the screen at the bottom, where it perefectly touches the other three sides. This is because, I made a change to: self.physicsBody=[SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(self.frame.origin.x, self.frame

Basic Swift SpriteKit Collisions using PhysicsBodys

社会主义新天地 提交于 2019-12-13 17:42:50
问题 The problem: I seem to be having a little trouble getting my player to collide with a coin, and adding +1 to a coinLabel upon the collision. The player should continue moving after coming in contact with the coin. What I have now: With the code I have now, the player travels through the coin, but there is no collision that takes place and +1 isn't added to the coin label. I am still learning the swift language, so I appreciate any help that is given. Code: struct ColliderType { static let

Swift SpriteKit basic Contact / Collision

放肆的年华 提交于 2019-12-13 07:15:12
问题 The problem: When the coin spawns, it's physicsBody appears right underneath the spriteNode. Also, when the player comes in contact with the coin's physicsBody, the player bounces off of the physicsBody and the game ends. What the output should be: The coin's physisBody should be aligned properly with the coin spriteNode. When the player comes in contact with the coin, the coin should disappear and +1 should be added to the proper label. The current code: struct ColliderType { static let

didBeginContact - bodyA & bodyB end Contact if one of them hits another category

流过昼夜 提交于 2019-12-13 03:55:28
问题 Here is the deal, I've got a basket, an Apple and an Orange bodies. We are going to drop them into the basket. I also want to know the presence of the Apple inside the basket, so I go ahead and add a didEndContact method. Lets assume the apple is already inside the basket. Now I drop the Orange in the basket, everything works fine until the Orange hits both the Apple and the surface which is the basket. As soon as the Orange hits the Apple while it's seating in the basket, Apple category ends