Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create wind effect in spritekit

Tags:

sprite-kit

I was playing angry birds and arrived at this stage where the wind "blows" you and kinda pushes you. was kinda interesting but I really couldnt figure the logic or code that would accomplish this. I know that you could probably use the emitter to create the wind like "look" but i would really like some insight on how you would accomplish the "pushing" of the sprite.

Thank you

like image 325
Sleep Paralysis Avatar asked Dec 18 '25 13:12

Sleep Paralysis


1 Answers

You are right about the fact that the emitter can only be used to give the illusion that a wind is blowing.

I am assuming here that you have physicsBodies attached to the nodes which are to be affected by the wind.

In your -update: method,

-(void)update:(CFTimeInterval)currentTime
{

    if (windOn)
    {
        for (SKNode *node in self.children)
        {
            if (node.physicsBody.categoryBitMask == whateverCategory)
            {
                [node.physicsBody applyForce:CGVectorMake(200, 0)];
            }
        }
    }
}  

This simulates a wind blowing from left to right. You will have to adjust the vector to achieve the desired direction and magnitude of the force.

like image 190
ZeMoon Avatar answered Dec 21 '25 22:12

ZeMoon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!