skphysicsbody

Stop SKSpriteNode from slowing down

隐身守侯 提交于 2019-12-07 15:32:44
问题 I am trying to keep my SKSpriteNodes moving at a constant speed forever, even after collisions. I have set gravity to 0, friction to 0, and linear and angular dampening to zero, but the Sprites still slowly slow down to zero velocity. How can I keep them moving? Based on the answer below, this is what I have tried: EDIT This code below works! I just had to check if the nodes were going slower than the limit and speed them up. [self enumerateChildNodesWithName:kBallName usingBlock:^(SKNode

Swift-Setting a physics body velocity by angle

本小妞迷上赌 提交于 2019-12-07 03:13:20
I was wondering if it was at all possible to make an SKNode move forward in a particular direction, but with only one factor. I'm aware of both applying an impulse and setting the velocity of a physics body, but they're both determined by two factors; dx and dy. I also know of rotating to an angle with SKActions. But is it possible to make an object simply "move forward" once it has been set on an angle? Or set its velocity with just one factor? Thanks in advance. Sure I think what you're talking about is something like this: Now let's say you have an SKSpriteNode that is called player who

SKshapenode is not responding to Physicsbody

风流意气都作罢 提交于 2019-12-06 13:44:30
I have created a SKShapeNode and I have assigned a physicsBody to it. However, it is not being triggered when there is contact. Creation of SKShapeNode code: -(SKShapeNode*)gravityline{ //SKSpriteNode *lolo=[[SKSpriteNode alloc]init]; SKShapeNode *lolo = [[SKShapeNode alloc] init]; CGPoint fff=CGPointMake(ray1.position.x, ray1.position.y); CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, fff.x, fff.y); CGPathAddLineToPoint(path, 0,rayoriginpoint.x,rayoriginpoint.y ); CGPathCloseSubpath(path); lolo.path = path; lolo.name=@"gravityline"; lolo.strokeColor=[SKColor

Friction in SpriteKit

此生再无相见时 提交于 2019-12-06 12:23:38
问题 I'm working with Swift, SpriteKit and Xcode 6, I have a circle node on my screen and I can change the node's position with my finger, but I would like to implement a friction effect to this node, but I don't now how to do so, here's my code : class PlayScene: SKScene { let firstCircle = SKSpriteNode(imageNamed: "Circle") // theses 3 variables allows me to move the node according to my finger, but my finger don't have to touch the node var departCircleLocation = CGPoint() var

Swift SpriteKit edgeLoopFromRect Issue

浪尽此生 提交于 2019-12-06 06:14:31
问题 The following code recognizes the bottom and top edges of the scene and the ball bounces off as expected. However, the left and right edges of the scene are breached all the time. The ball goes off screen and then eventually returns back if enough force is applied. It is as if the edges of the scene are beyond the edges of the iphone simulator window. import SpriteKit class GameScene: SKScene { override func didMoveToView(view: SKView){ self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self

How to apply impulse to the node on touch angle

人盡茶涼 提交于 2019-12-06 06:04:46
I want the node to move in the right direction but the impulse to be with set strength. let node: SKSpriteNode!; node = SKSpriteNode(color: UIColor.greenColor(), size: CGSizeMake(50, 50)); node.physicsBody = SKPhysicsBody(rectangleOfSize: node.size); node.physicsBody?.affectedByGravity = false; node.physicsBody?.allowsRotation = false; override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { node.physicsBody?.velocity = CGVectorMake(0, 0); // ver 1 node.physicsBody?.applyImpulse(CGVectorMake((0.4) * (location.x - node.position.x), (0.4) * (location.y - node.position.y)),

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

狂风中的少年 提交于 2019-12-06 05:39:05
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? You can create a concave physics body by adding up a bunch of convex physics bodies into one shape. Then you can add them as children to an

Stop SKSpriteNode from slowing down

…衆ロ難τιáo~ 提交于 2019-12-06 03:38:42
I am trying to keep my SKSpriteNodes moving at a constant speed forever, even after collisions. I have set gravity to 0, friction to 0, and linear and angular dampening to zero, but the Sprites still slowly slow down to zero velocity. How can I keep them moving? Based on the answer below, this is what I have tried: EDIT This code below works! I just had to check if the nodes were going slower than the limit and speed them up. [self enumerateChildNodesWithName:kBallName usingBlock:^(SKNode *node, BOOL *stop) { SKSpriteNode *ball = (SKSpriteNode *)node; if (ball.physicsBody.velocity.dx < 0) { if

SKPhysicsBody with restitution 0 still bounces

一个人想着一个人 提交于 2019-12-05 22:43:10
I'm am trying to drop the SKSpriteNode with constant speed and without bouncing. Here is the code I'm using: SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)]; floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size]; floor.physicsBody.restitution = 0.0f; floor.physicsBody.dynamic = NO; floor.physicsBody.allowsRotation = NO; SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:imageName]]; block.position = CGPointMake(160, 300); block.physicsBody = [SKPhysicsBody

iOS Swift didBeginContact not being called

早过忘川 提交于 2019-12-05 22:09:06
问题 I have been struggling for the past two days to get two SKSpriteNodes to register a collision and evoke didBegin#contact . I've set their bit masks ' categoryBitMask ', ' contactTestBitMask ' and ' collisionTestBitMask ' for both objects. I've also set the ' dynamic ' property for both to ' true ' initPhysics() seems to set up the physicsWorld okay. All I'm expecting is that didBegin#Contact is called, but it is not //Set up Physicsbody bit masks let playerCarBitMask: UInt32 = 0x1 << 1 let