skphysicsbody

Is there a way to make a soft body with Spritekit using SKSpriteNode and PhysicsBody parameters?

做~自己de王妃 提交于 2019-12-21 20:06:07
问题 I have the following sprite that falls to the bottom of the screen: // The View self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; self.physicsWorld.contactDelegate = self; // The Sprite SKSpriteNode *cube = [[SKSpriteNode alloc] initWithImageNamed:@"cube"]; [cube setPosition:CGPointMake(160,250); [self addChild:cube]; // The Physics cube.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:cube.frame.size]; cube.physicsBody.dynamic = YES; cube.physicsBody

How can I apply an angular impulse to a Sprite Kit node based on a pan gesture velocity

本秂侑毒 提交于 2019-12-21 06:27:21
问题 What I'm looking to do here is to spin a SKSpriteNode around its anchor point and have its speed and direction match a pan gesture. So if my pan gesture is clockwise around the sprite then then sprite spins clockwise. The problem I have with my code is that it works great for pans below the sprite from left to right/right to left, but not at all when I try and pan vertically and it makes the sprite spin the wrong way if I pan above the sprite. Here's what I've got so far - let windmill =

Sprite Kit bodyAtPoint and bodyInRect return incorrect values?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 04:57:04
问题 I created a very simple sample code, just one scene, one sprite node 20x20px, at point 0.0 on screen. When I call scene.physicsWorld bodyAtPoint it returns me this node even at point eg: 34x34. But at point 35x35 it returns null . So basically all points from 0px to 34px in both axis returns this node, starting from 35px, it doesn't return it anymore. Any idea what could be the reason, if sprite visibly ends at 20px 20px? The same behaviour is seen in bodyInRect . Here is the sample code: -

How to Fit the Physics Body Size of an SKSpriteNode to its Image in Xcode Using SpriteKit

╄→尐↘猪︶ㄣ 提交于 2019-12-20 07:20:58
问题 So I'm not sure if this is possible, but I am trying to adapt the physics body to go with my image. Many people have told me that the hitbox for the character in my game on the iOS App Store (StreakDash - go download it!) does not work well, since it makes the game a lot harder (the hitbox hits an obstacle even though the character doesn't appear to even be touching it). This is due to the fact that the hitboxes are rectangular, whereas my character has a strange shape. Are there any ways to

contacts not recognized when body is changed from circle to rectangle

孤人 提交于 2019-12-20 04:55:56
问题 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

How to get SKSpriteNode by physicsBody?

梦想与她 提交于 2019-12-19 11:35:44
问题 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

SpriteKit move rotated physicsBody with applyImpulse

喜欢而已 提交于 2019-12-19 10:46:26
问题 I want to move a physicsBody with the applyImpulse method in a direction based on the physicsBody rotation. Foe example, the physicsBody is a square in shape, I call a "move" which will apply an impulse to make it move up vertically. I then call a method to rotate the physicsBody 45 degrees right. If I call the "move" method again, the physicsBody will move diagonally right and up. Can anyone help please? 回答1: I suggest that you follow Sprite Kit’s coordinate and rotation conventions.

SpriteKit iPhone/iPad different resolution, need same physics

允我心安 提交于 2019-12-18 20:54:23
问题 As I am porting an iPhone app that uses SpriteKit to iPad, I have been able to scale all the screen elements and font sizes using the height ratio of the iPhone 5 to iPad screen. Everything looks proportional, except for the physics since there is more area. So the question is, how do I scale the physics along with the screen using that height ratio? Perhaps changing density or mass of all the nodes? How would I do it, mathematically using the ratio so that it is perfect? 回答1: You can

Physics detecting collision multiple times

帅比萌擦擦* 提交于 2019-12-18 09:09:20
问题 When the ball collides with the cup, the score should increase by 1. However it currently increases by 1, 3 or sometimes 4 which means the collision is being detected multiple times. I think I must be checking for collisions incorrectly: let ballCategory : UInt32 = 0x1 << 0 let cupCategory : UInt32 = 0x1 << 1 And in my didMoveToView : //Set physicsBody of scene to a physics body that borders the screen self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame) physicsWorld.contactDelegate

Flipped x-scale breaks collision handling (SpriteKit 7.1)

二次信任 提交于 2019-12-18 03:38:10
问题 I use SKNode's xScale property to flip my sprites horizontally. Now, after updating iOS to version 7.1 horizontal flip causes my objects to sink inside the ground. (See animation below). The problem occurs only with xScale property. Vertical flips work fine. // Init { SKSpriteNode* ground = [SKSpriteNode spriteNodeWithColor:[UIColor blackColor] size:CGSizeMake(winSize.width, 150)]; ground.position = CGPointMake(winSize.width/2, ground.size.height/2); ground.physicsBody = [SKPhysicsBody