如何在 spritekit 中创建风效果 [英] How to create wind effect in spritekit

查看:23
本文介绍了如何在 spritekit 中创建风效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩愤怒的小鸟,到了这个风吹"你,有点推你的阶段.有点有趣,但我真的想不出实现这一点的逻辑或代码.我知道你可能会使用发射器来创造像看"这样的风但我真的很想了解你将如何完成精灵的推动".

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.

谢谢

推荐答案

你说得对,发射器只能用来产生风在吹的错觉.

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

我在这里假设您将physicsBodies 附加到要受风影响的节点上.

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

在您的 -update: 方法中,

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.

这篇关于如何在 spritekit 中创建风效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆