How to create wind effect in spritekit

前端 未结 1 1049
南方客
南方客 2021-01-06 15:29

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 th

相关标签:
1条回答
  • 2021-01-06 15:41

    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.

    0 讨论(0)
提交回复
热议问题