<?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: Selecting Sprite inside function, Best Practice?</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/2555</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 01:44:19 +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/2555" rel="self" type="application/rss+xml" />

		<item>
			<title>ddeaco on "Selecting Sprite inside function, Best Practice?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2555#post-15920</link>
			<pubDate>Mon, 19 Oct 2009 17:39:11 +0000</pubDate>
			<dc:creator>ddeaco</dc:creator>
			<guid isPermaLink="false">15920@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks Mr Codemattic
</p></description>
		</item>
		<item>
			<title>Codemattic on "Selecting Sprite inside function, Best Practice?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2555#post-15918</link>
			<pubDate>Mon, 19 Oct 2009 17:03:18 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">15918@http://www.cocos2d-iphone.org/forum/</guid>
			<description><pre><code>Sprite *block = nil;
if(c == 1){
 block = [[Sprite spriteWithFile:@&#34;green.png&#34;] retain];
}
if(c == 2){
 block = [[Sprite spriteWithFile:@&#34;red.png&#34;] retain];
}
if(c == 3){
 block = [[Sprite spriteWithFile:@&#34;blue.png&#34;] retain];
}
if (block!=nil) [self addChild: block z:1 tag:blockSprite];</code></pre>
<p>or<br />
<pre><code>Sprite *block = nil;
if(c == 1){
 block = [[Sprite spriteWithFile:@&#34;green.png&#34;] retain];
} else if(c == 2){
 block = [[Sprite spriteWithFile:@&#34;red.png&#34;] retain];
} else if(c == 3){
 block = [[Sprite spriteWithFile:@&#34;blue.png&#34;] retain];
} else return;
[self addChild: block z:1 tag:blockSprite];</code></pre></description>
		</item>
		<item>
			<title>ddeaco on "Selecting Sprite inside function, Best Practice?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2555#post-15916</link>
			<pubDate>Mon, 19 Oct 2009 16:44:14 +0000</pubDate>
			<dc:creator>ddeaco</dc:creator>
			<guid isPermaLink="false">15916@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everyone,</p>
<p>I'm currently trying my best to tidy up my code and reduce the number of functions I have. In doing so I would like to pass in an integer into my function that defines which sprite to use.</p>
<p>This is where I'm having a problem, using IF statements causes XCode to not see me declaring which sprite to use and gives me an declared error, and also list all of my sprite declarations as 'unused variables' warnings.</p>
<p>Ive tried declaring it before the IF statements but it doesn't allow me to redefine it.</p>
<p><code><br />
//c is passed in when calling the function.<br />
if(c == 1){<br />
	Sprite *block = [[Sprite spriteWithFile:@"green.png"] retain];<br />
}<br />
if(c == 2){<br />
	Sprite *block = [[Sprite spriteWithFile:@"red.png"] retain];<br />
}<br />
if(c == 3){<br />
	Sprite *block = [[Sprite spriteWithFile:@"blue.png"] retain];<br />
}</p>
<p>[self addChild: block z:1 tag:blockSprite];<br />
</code></p>
<p>I'm pretty sure this is a simple fix I've spent a while trying different things, and Google'ing the problem but I cant quite get it to work.
</p></description>
		</item>

	</channel>
</rss>

