如何正确打开和关闭SKNode的SKEffectNode? [英] How to correctly turn on and off SKEffectNode for a SKNode?

查看:399
本文介绍了如何正确打开和关闭SKNode的SKEffectNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择了节点,我想显示效果节点。如果没有,我想关闭/删除该效果。 (我在 touchesBegan 中设置了一个节点。)

I want to show an effect node if a node is selected. If not, I want to turn off/remove that effect. (I set a node as selected in touchesBegan.)

我使用下面的代码。打开和关闭效果节点是我的想法,因为我将主节点添加到效果节点。如何在不丢失主节点的情况下将其关闭?我可以将效果的颜色更改为透明以隐藏它但听起来不是正确的方法...将主节点从效果节点移动到效果节点的父节点可能会起作用但我必须重新定位它以使它不会听起来也是正确的方式..

I use the code below. Turning on and off the effect node is mixing my mind up because I add the main node into an effect node. How should I turn it off without loosing the main node too? I can change the color of the effect to transparent to hide it but it doesn't sound like the right way... Moving main node from effect node to parent of effect node may work but I have to reposition it again so it doesn't sound like the right way too..

这样做的正确方法之一是什么? (正确=有利于提高性能而不会增加编码复杂性)

What is one of the correct ways of doing this? (correct = good for performance while not increasing coding complexity)

SKShapeNode* tile = [SKShapeNode node];
[tile setPath:CGPathCreateWithRoundedRect(CGRectMake(0, 0, 60, 100), 4, 4, nil)];
tile.strokeColor = tile.fillColor = [UIColor colorWithRed:0.0/255.0
                                                        green:128.0/255.0
                                                         blue:255.0/255.0
                                                        alpha:1.0];
tile.position = CGPointMake(10, 100);

SKEffectNode *effectNode = [[SKEffectNode alloc] init];
GlowFilter *glowFilter = [[GlowFilter alloc] init];
[glowFilter setGlowColor:[[UIColor yellowColor] colorWithAlphaComponent:1]];
[effectNode setShouldRasterize:YES];
[effectNode setFilter:glowFilter];
effectNode.position=CGPointMake(0, 0);
[effectNode addChild:tile];

[self addChild:effectNode];


推荐答案

theEffectNode.shouldEnableEffects = NO;

这篇关于如何正确打开和关闭SKNode的SKEffectNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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