<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Topic: Possible to FadeOut an entire Layer?</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/2131</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 02:03:17 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/topic/2131" rel="self" type="application/rss+xml" />

		<item>
			<title>Codemattic on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13481</link>
			<pubDate>Sun, 27 Sep 2009 03:12:59 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">13481@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>"This is strange. Codemattic is correct" actually... its the -visit method which will call the children's -draw, so I am wrong about that.  D'oh.  Sorry - but try splitting it up anyway and see if that works - if not, then something is probably wrong with the sprites themselves.
</p></description>
		</item>
		<item>
			<title>Mitch Lindgren on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13476</link>
			<pubDate>Sun, 27 Sep 2009 02:21:17 +0000</pubDate>
			<dc:creator>Mitch Lindgren</dc:creator>
			<guid isPermaLink="false">13476@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is strange.  Codemattic is correct, but I have a class in my project which is a subclass of ColorLayer, and I've never had any problems with it - children are drawn fine.  I don't override the draw method, either.  Hm...
</p></description>
		</item>
		<item>
			<title>Codemattic on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13432</link>
			<pubDate>Sat, 26 Sep 2009 18:26:52 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">13432@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>It doesnt look like ColorLayer's -draw calls [super draw], so none of its children will ever be drawn.  Create a Layer or Node, add your ColorLayer at the bottom and any Sprites you want above that.
</p></description>
		</item>
		<item>
			<title>ghostradio on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13426</link>
			<pubDate>Sat, 26 Sep 2009 16:24:21 +0000</pubDate>
			<dc:creator>ghostradio</dc:creator>
			<guid isPermaLink="false">13426@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks for the suggestions guys - but I'm still trying to find the answer to one question: Can other children be added to ColorLayers? I can't seem to see any children that I add to one, but they still initialize and run (according to some NSLog statements I have in them.)
</p></description>
		</item>
		<item>
			<title>Scoobadood on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13396</link>
			<pubDate>Sat, 26 Sep 2009 03:05:33 +0000</pubDate>
			<dc:creator>Scoobadood</dc:creator>
			<guid isPermaLink="false">13396@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/133'>Mark</a><br />
Nice solution - often simple is best :)
</p></description>
		</item>
		<item>
			<title>Mark Sawicki on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13389</link>
			<pubDate>Sat, 26 Sep 2009 02:06:46 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">13389@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Just a thought, but I would think it would be super simple to achieve that effect with adding a layer , and fading it IN to cover the screen, then while the screen is completely opaque, remove your other layer, then fade that top layer out and start your game loop.</p>
<p>Mark
</p></description>
		</item>
		<item>
			<title>Scoobadood on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13386</link>
			<pubDate>Sat, 26 Sep 2009 01:45:56 +0000</pubDate>
			<dc:creator>Scoobadood</dc:creator>
			<guid isPermaLink="false">13386@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I had the same issue which I've 'fixed' like this:</p>
<p>The Layer class itself doesn't support opacity because it's basically a 'see through' container for it's children.</p>
<p>To fade a Layer you really just want to fade all of it's children. You can do this as follows:</p>
<p>On your Layer subclass, add the following:</p>
<pre><code>// Set the opacity of all of our children that support it
-(void) setOpacity: (GLubyte) opacity
{
    for( CocosNode *node in [self children] )
    {
        if( [node conformsToProtocol:@protocol( CocosNodeRGBA)] )
        {
            [(id&#60;CocosNodeRGBA&#62;) node setOpacity: opacity];
        }
    }
}</code></pre>
<p>This method forwards the setOpacity call to each child of the Layer to make sure they all fade. The important bit is the check to make sure that the node actually supports setOpacity in the first place.</p>
<p>Generally, any class which supports setting opacity implements the <code>CocosNodeRGBA</code> protocol so this is what we check for.</p>
<p>Note that we could just test to see if the method is supported using:</p>
<p><code>if( [node respondsToSelector:@selector( setOpacity:)] )</code></p>
<p>The problem with this is that in the body of the <code>if</code> statement we then try to call <code>setOpacity</code> and the compiler will warn us that this may not be supported. Not a real problem but it's nice to avoid upsetting the compiler :)</p>
<p><strong>Note</strong><br />
This works for me but there is a potential problem. If a child of the node doesn't support <code>setOpacity</code> then it won't be faded so you will have to handle this. The code above doesn't.</p>
<p>One option would be to turn visibility of the child off if opacity is 0 and on if it's not. You could change the method above to implement this :</p>
<pre><code>// Set the opacity of all of our children that support it
-(void) setOpacity: (GLubyte) opacity
{
    for( CocosNode *node in [self children] )
    {
        if( [node conformsToProtocol:@protocol( CocosNodeRGBA)] )
        {
            [(id&#60;CocosNodeRGBA&#62;) node setOpacity: opacity];
        }
        // Handle children that don&#39;t support opacity
        else
        {
            node.visible = ( opacity != 0 );
        }
    }
}</code></pre>
<p>This will work but might be a bit of an ugly solution as children will pop in and out if they don't support opacity.</p>
<p>A better solution, and the one I ended up implementing, is to find any children that don't implement opacity (and there aren't that many of them) and subclass them, adding your own <code>setOpacity</code> method as above.</p>
<p>Hope this helps<br />
ScoobaDood</p>
<p>&#60;ShamelessPlug&#62;<br />
Check out Shape Up! at <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=329995992&#038;mt=8" rel="nofollow">http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=329995992&#038;mt=8</a><br />
&#60;/ShamelessPlug&#62;
</p></description>
		</item>
		<item>
			<title>ghostradio on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13372</link>
			<pubDate>Fri, 25 Sep 2009 22:59:33 +0000</pubDate>
			<dc:creator>ghostradio</dc:creator>
			<guid isPermaLink="false">13372@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So I've changed my MenuLayer to be a subclass of ColorLayer, and I'm getting the fade effect like I want, but only for the solid color that I init the layer with. I can't see any of the children that I've added to the Layer now. Can I not add children to a ColorLayer?
</p></description>
		</item>
		<item>
			<title>Mitch Lindgren on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13364</link>
			<pubDate>Fri, 25 Sep 2009 22:28:05 +0000</pubDate>
			<dc:creator>Mitch Lindgren</dc:creator>
			<guid isPermaLink="false">13364@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>You can't use FadeOut on any node that doesn't support the CocosNodeRGBA protocol, so using it on an entire layer is potentially dangerous - if any children don't support the protocol, an exception will be generated.
</p></description>
		</item>
		<item>
			<title>ghostradio on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13363</link>
			<pubDate>Fri, 25 Sep 2009 22:25:22 +0000</pubDate>
			<dc:creator>ghostradio</dc:creator>
			<guid isPermaLink="false">13363@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Are there any limitations to what sort of nodes this works on? I'm trying to do something very similar:</p>
<p><code>FadeOut *fader = [FadeOut actionWithDuration:1];<br />
		[menuLayer runAction:fader];</code></p>
<p>but every time I tell the action to run on the menuLayer, I get the following error:</p>
<p>2009-09-25 16:20:43.802 PROJECTNAME[392:207] *** -[MenuLayer setOpacity:]: unrecognized selector sent to instance 0x651d3b0<br />
2009-09-25 16:20:43.805 PROJECTNAME[392:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MenuLayer setOpacity:]: unrecognized selector sent to instance 0x651d3b0'</p>
<p><code>MenuLayer</code> is a subclass of Layer.
</p></description>
		</item>
		<item>
			<title>natanavra on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13358</link>
			<pubDate>Fri, 25 Sep 2009 21:26:18 +0000</pubDate>
			<dc:creator>natanavra</dc:creator>
			<guid isPermaLink="false">13358@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Glad I could help!
</p></description>
		</item>
		<item>
			<title>stevef on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13357</link>
			<pubDate>Fri, 25 Sep 2009 21:21:49 +0000</pubDate>
			<dc:creator>stevef</dc:creator>
			<guid isPermaLink="false">13357@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks man, worked perfectly!
</p></description>
		</item>
		<item>
			<title>natanavra on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13354</link>
			<pubDate>Fri, 25 Sep 2009 21:07:54 +0000</pubDate>
			<dc:creator>natanavra</dc:creator>
			<guid isPermaLink="false">13354@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>OK, gotch'a!<br />
Transition are used purely for Scenes...<br />
You can use animations on any CocosNode and it should affect the node's children...<br />
So you could write something like:</p>
<p><code>[menuLayer runAction:[FadeOut actionWithDuration: ....]];</code></p>
<p>This should fade the whole layer + it's children...</p>
<p>~ Natanavra.
</p></description>
		</item>
		<item>
			<title>stevef on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13353</link>
			<pubDate>Fri, 25 Sep 2009 21:03:59 +0000</pubDate>
			<dc:creator>stevef</dc:creator>
			<guid isPermaLink="false">13353@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks for the reply Natanavra. I think that only takes a Scene, unless a Layer subclasses Scene. (I'll have to double check the object graph) I basically just want to fade out the entire Menu and not bring it back in.
</p></description>
		</item>
		<item>
			<title>natanavra on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13352</link>
			<pubDate>Fri, 25 Sep 2009 20:57:39 +0000</pubDate>
			<dc:creator>natanavra</dc:creator>
			<guid isPermaLink="false">13352@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Animations can be applied on any CocosNode (right?) including Layers and Scenes.</p>
<p>Although I wouldn't suggest using animations, you have transitions... and Scene management through director... so it might look something like this:</p>
<p><code>[[Director sharedDirector] replaceScene:[FadeTransition transitionWithDuration:1.0 scene: [GameScene node]];</code></p>
<p>(Non-checked, dirty code... but the concept is right...)</p>
<p>~ Natanavra.
</p></description>
		</item>
		<item>
			<title>stevef on "Possible to FadeOut an entire Layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2131#post-13349</link>
			<pubDate>Fri, 25 Sep 2009 20:45:34 +0000</pubDate>
			<dc:creator>stevef</dc:creator>
			<guid isPermaLink="false">13349@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all,</p>
<p>I have a simple subclass of Scene and a Layer on top of it with a Menu. Basically I'm just following along the tutorial on: <a href="http://monoclestudios.com/cocos2d_whitepaper.html" rel="nofollow">http://monoclestudios.com/cocos2d_whitepaper.html</a></p>
<p>Curious now, once a user hits startGame(), I'd like to be able to fade the entire MenuLayer out and start my game loop.</p>
<p>The menu was created like this:</p>
<p><code><br />
@implementation MenuLayer<br />
- (id) init {<br />
	self = [super init];<br />
	if (self != nil) {<br />
		[MenuItemFont setFontSize:20];<br />
		[MenuItemFont setFontName:@"Helvetica"];<br />
		MenuItem *start = [MenuItemFont itemFromString:@"Start Game" target:self selector:@selector(startGame:)];<br />
		MenuItem *help = [MenuItemFont itemFromString:@"Help" target:self selector:@selector(help:)];<br />
		Menu *menu = [Menu menuWithItems:start, help, nil];<br />
		[menu alignItemsVertically];<br />
		[self addChild:menu];<br />
	}&#60;/p&#62;<br />
&#60;p&#62;	return self;<br />
}<br />
</code></p>
<p>I've found the FadeOut action, but can it be applied to a Layer here or only Sprite types?
</p></description>
		</item>

	</channel>
</rss>

