skphysicsbody

SKAction scaleXTo:-1

旧巷老猫 提交于 2019-12-11 06:46:56
问题 I am trying to mirror my SKSpriteNode using SKAction *mirrorDirection = [SKAction scaleXTo:-1 y:1 duration:0.0]; but every time I do, the sprite's physics body seems to get messed up and it drops off the screen. I have several objects (floors) beneath the sprite and it falls through all of them as if they are not there. This only happens when I mirror the sprite. Anyone know how to fix this? Update: Reseting the physics body as one answer suggested unfortunately did not fix the problem. It

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

How to give screen edge a physics body

…衆ロ難τιáo~ 提交于 2019-12-11 03:44:08
问题 I have a background sprite that I would like to give physics body. background.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(screenWidth , screenHeight)]; The problem is that the sprites are within the screen bounds and Im trying to detected collision with those sprites when they hit the edge of the screen. Instead its automatically detecting collision because my sprites are already within the physics body of the background. What do I do? Update:Above question is answered for

Physics body size not changing with SKSpriteNode size change in Touch moved method

巧了我就是萌 提交于 2019-12-10 16:55:28
问题 I am trying to create a spring launcher where when touch is moved on scene the spring will coil as much the touch is dragged down and thn launch the item above the spring on touch end method. For that i changed the size and position of SKSpriteNode in touch move method as - launcher.position = CGPointMake(frame.size.width*0.97, launcher.position.y-1) launcher.size = CGSizeMake(frame.size.width*0.05, launcher.frame.size.height-2) But the Physics body of SKSpriteNode not changing it comes like

Swift-Setting a physics body velocity by angle

吃可爱长大的小学妹 提交于 2019-12-08 05:06:33
问题 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. 回答1: Sure I think what you

SpriteKit: Sprites are moving through each other with a physicsBody already set

Deadly 提交于 2019-12-08 04:28:12
问题 So I have created a player who moves tile based and a wall surrounding the map to keep the player on the playground. Both have a physicsBody in them. My guess is, that my movement of the player is not properly and so the player bugs into the walls. Let me just show you my code: So this is the physicsBody of the Player: self.physicsBody!.usesPreciseCollisionDetection = true self.physicsBody!.categoryBitMask = PhysicsCategory.Player self.physicsBody!.contactTestBitMask = PhysicsCategory.House

Touch Sprite, make it jump up then fall down again(repeat as many times as spritenode is tapped.)

北战南征 提交于 2019-12-08 03:15:04
问题 I created a project where I have a ball and when the view loads, it falls down, which is good. I'm trying to get the ball to jump back up and fall down again when the Spritenode is tapped. --This Question was edited-- Originally, I was able to get it to work when sprite.userInteractionEnabled = false . I had to turn this statement true in order to get the score to change. Now I can't get the balls to fall and be tapped to jump. When I turn ball.physicsBody?.dynamic = true , the balls will

SKshapenode is not responding to Physicsbody

社会主义新天地 提交于 2019-12-07 22:55:28
问题 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

SKPhysicsBody with restitution 0 still bounces

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 17:35:25
问题 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

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,