Why is SKSpriteNode not responding to applyForce or applyImpulse?

I have a node sprite that appears and falls in response to the gravity superimposed on it attached physicsBody.

Great.

Now I would like to use applyForceto push it a little in some direction while it falls.

Unfortunately, no matter how small I am doing physicsBody.massor physicsWorld.gravityis or how I'm doing the vector applyForce- vector applyForceseems to be ignored.

When I comment out a line self.physicsWorld.gravity , I see the applyForce work as expected

How to achieve a "push" of a physical body using applyForce with gravity?


Here is my .h

// GameScene.h


#import <SpriteKit/SpriteKit.h>

@interface GameScene : SKScene

@end

And .m

// GameScene.m

#import "GameScene.h"

@interface GameScene ()
@property NSMutableArray *bubblesToPop;

@end

@implementation GameScene

-(void)didMoveToView:(SKView *)view {
    /* Setup your scene here */

    self.size = view.bounds.size;
    self.physicsWorld.gravity = CGVectorMake(0, 1.0);

    SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"bubble"];

    sprite.yScale = 0.5;
    sprite.xScale = 0.5;
    sprite.name = @"bubble";
    sprite.position = CGPointMake(self.frame.size.width / 2.0, self.frame.size.height / 2.0);

    SKPhysicsBody *physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.frame.size.width];
    physicsBody.mass = 0.02;
    [physicsBody applyForce:CGVectorMake(900, 900)];
    sprite.physicsBody = physicsBody;

    [self addChild:sprite];

}

@end
+4
1

, Sprite Kit , . applyForce addChild .

Apple:

. - node node. node s , ... , , nodetree.. , . node [ ].

, , . , , (iOS 8) , . , Sprite Kit , .

+4

All Articles