I have a sprite node that's appearing and falling in response to the gravity applied on its attached physicsBody
.
Great.
Now, I'd like to use applyForce
to push it a little bit in some direction while it's falling.
Unfortunately, no matter how small I make the physicsBody.mass
or physicsWorld.gravity
or how large I make the applyForce
vector -- the applyForce
vector appears to be ignored.
When I comment out the self.physicsWorld.gravity
line, I see applyForce
working as expected
How do I achieve "pushing" the physics body using applyForce whilst gravity is applied?
Here's my .h
// GameScene.h
#import <SpriteKit/SpriteKit.h>
@interface GameScene : SKScene
@end
And the .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