In my spritekit game I am working on applying a wind like force to my game. I have somehow implemented this a number of ways.
The first way I tried is this : Attempt one In this code here the sprite is first pushed as it should, however I cant get it too stop.
-(void)update:(NSTimeInterval)currentTime {
NSLog(@" %d",_time);
if (_time == 200 /* | _time==400 */ ) {
[self startPush];
}
-(void)startPush
{
SKAction *startPush = [SKAction runBlock:^{
[_player.physicsBody applyForce:CGVectorMake(50, 0)];
}];
SKAction *wait = [SKAction waitForDuration:1];
SKAction *stopPush = [SKAction runBlock:^{
// [_player.physicsBody applyForce:CGVectorMake(-50, 0)];
[_player.physicsBody applyForce:CGVectorMake(0, 0)];
}];
SKAction *sequence = [SKAction sequence:@[startPush, wait,stopPush]];
[self runAction:sequence];
}
Attempt Two I attempted to change my code since i saw this post by LearnCocos2d where he said that AKActions are bad for movements.
Constant movement in SpriteKit
So i tried this
Here also the pushing doesnt stop even if pushOn is set to No. Would love some help in doing the final tweaks in this.
Thank you
-(void)update:(NSTimeInterval)currentTime {
NSLog(@" %d",_time);
if (_time == 200 /* | _time==400 */ ) {
windOn=NO;
}else if (_time==300)
{
pushOn=NO;
}
if (pushOn)
{
{
[_player.physicsBody applyForce:CGVectorMake(0.1, 0)];
}