skphysicsbody

bodyWithEdgeLoopFromRect not working in landscape

半城伤御伤魂 提交于 2020-01-24 06:03:32
问题 I'm just trying to set up a basic scene in landscape, with gravity, and having the scene in an edge loop. I set up the scene's physics body and the mainCharacter sprite physics body, here is my code: -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor redColor]; [self setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromRect:[self frame]]]; } return self; } -(void)setupMain { if (!self.mainCharacter) { self.mainCharacter = [[SKSpriteNode alloc

How to detect a collision in sprite kit?

好久不见. 提交于 2020-01-13 18:01:46
问题 I am making a game in Sprite Kit and I have struggles with the collision detection between SpriteNodes, I've set a sprite node called sprite and a sprite node called platform. I want the sprite to stop falling when collided with the platform. This is what I have: SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"bal.png"]; sprite.position = CGPointMake(self.frame.size.width/4 + arc4random() % ((int)self.frame.size.width/2), (self.frame.size.height/2 + arc4random() % ((int)self

Can I move dynamic physics bodies using SKAction when only contact detection is needed?

蓝咒 提交于 2020-01-13 06:28:06
问题 I am looking at tutorial where things are defined like this: planes are sprites with dynamic physics bodies plane moving is done with actions by following the path there is contact detection between bullet and plane bullet is sprite and it has physics body set to be static (which is little unusual in my opinion) Here is the link to tutorial for more information. Questions: When we use actions to move physicsBodies is there a difference how we set body's dynamic property? Because bullet is

Change a SKPhysicsBody's body shape

為{幸葍}努か 提交于 2020-01-03 21:08:45
问题 I don't want to change ANYTHING other than the body that defines the shape of a SKPhysicsBody. How do I do this? I can't seem to find where I can change this. Or even commentary on how to change it. Yes, I know this has to be done carefully, so that it avoids all possible new collisions, overlaps, etc. But putting that aside, how do I change the body of an SKPhysicsBody? 回答1: You can manually create a custom shape for a physics body using CGMutablePath , then pass it into the SKPhysicsBody

How to apply impulse to the node on touch angle

房东的猫 提交于 2020-01-02 18:06:33
问题 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?

Sprite Kit Physics Collision Issue

自古美人都是妖i 提交于 2020-01-02 03:47:06
问题 I'm having an issue with some collisions. I have two objects equal size and mass. When one collides into another that is at rest I get the correct behavior (grey area in image). When I have two objects that are next to each other the behavior isn't quite right. Spritekit result on the left. Expected/needed result on right. I think I know what is going on, but not sure what to do about it. If the object was one object with twice the mass then the spritekit behavior would be correct, but they

How to detect contact on different areas of a physicsbody

亡梦爱人 提交于 2019-12-31 03:22:01
问题 I would like to achieve the classic 'headshot' effect in a sprite-kit game. My ideas and attempts: Create separate 'body' and 'head' physicsBodies on the same sprite and pin them with a joint. Impossible :( Create a 'body' physics body on the "enemy" sprite and create another transparent sprite with a 'head' physicsBody that follows the body (sits on top). This approach requires me to keep track of what head is associated with what body. It will also decrease the games efficiency. I am

How to detect contact on different areas of a physicsbody

时间秒杀一切 提交于 2019-12-31 03:21:04
问题 I would like to achieve the classic 'headshot' effect in a sprite-kit game. My ideas and attempts: Create separate 'body' and 'head' physicsBodies on the same sprite and pin them with a joint. Impossible :( Create a 'body' physics body on the "enemy" sprite and create another transparent sprite with a 'head' physicsBody that follows the body (sits on top). This approach requires me to keep track of what head is associated with what body. It will also decrease the games efficiency. I am

Sprite Kit - Detecting Y due to an impulse and Gravity, if the ball is moving away or Closer to the ground

吃可爱长大的小学妹 提交于 2019-12-25 02:47:53
问题 I'm creating a false shadow for an SKSpriteNode (a Ball) with physicsBody and impulse in Y direction applied to it. I like to decrease the opacity of the shadow which stays on the ground as the ball raise and decrease it back to 100% as it heads back toward the ground. any Idea? 回答1: Yes, use the update method. Then simply test the balls Y position on every update. Add the ball to your scene. Add a shadow to your scene. In the update method of your scene (called at every frame by SpriteKit)

applyForce is not smooth

不想你离开。 提交于 2019-12-24 14:16:55
问题 Hopefully someone can help. I have been pulling my hair out on this one! Below is some of the control pad code from my Sprite Kit game which uses applyForce to move the hero ship. I like how the controls and movement feel, its got some nice drift, etc... However I have inconsistent results on the animation/movement it produces. Sometimes (about half the time) the animation is perfectly smooth and looks correct. The rest of the time the ship movement animation stutters at different intensities