<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>残酷の青春 &#187; 全部</title>
	<atom:link href="http://www.cruelyouth.com/subjects/all/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cruelyouth.com</link>
	<description>journey continues</description>
	<lastBuildDate>Tue, 17 Jan 2012 06:53:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>密码保护：关于最近的一点想法</title>
		<link>http://www.cruelyouth.com/2012/01/17/%e5%85%b3%e4%ba%8e%e6%9c%80%e8%bf%91%e7%9a%84%e4%b8%80%e7%82%b9%e6%83%b3%e6%b3%95/</link>
		<comments>http://www.cruelyouth.com/2012/01/17/%e5%85%b3%e4%ba%8e%e6%9c%80%e8%bf%91%e7%9a%84%e4%b8%80%e7%82%b9%e6%83%b3%e6%b3%95/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 06:51:36 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=937</guid>
		<description><![CDATA[无法提供摘要。这是一篇受保护的文章。]]></description>
			<content:encoded><![CDATA[<form action="http://www.cruelyouth.com/wp-pass.php" method="post">
<p>这是一篇受密码保护的文章。您需要提供访问密码：</p>
<p><label for="pwbox-937">密码：<br />
<input name="post_password" id="pwbox-937" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="提交" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2012/01/17/%e5%85%b3%e4%ba%8e%e6%9c%80%e8%bf%91%e7%9a%84%e4%b8%80%e7%82%b9%e6%83%b3%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我收藏的科技博客</title>
		<link>http://www.cruelyouth.com/2012/01/16/%e6%88%91%e6%94%b6%e8%97%8f%e7%9a%84%e7%a7%91%e6%8a%80%e5%8d%9a%e5%ae%a2/</link>
		<comments>http://www.cruelyouth.com/2012/01/16/%e6%88%91%e6%94%b6%e8%97%8f%e7%9a%84%e7%a7%91%e6%8a%80%e5%8d%9a%e5%ae%a2/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 01:50:44 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=923</guid>
		<description><![CDATA[http://thenextweb.com/]]></description>
			<content:encoded><![CDATA[<p>http://thenextweb.com/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2012/01/16/%e6%88%91%e6%94%b6%e8%97%8f%e7%9a%84%e7%a7%91%e6%8a%80%e5%8d%9a%e5%ae%a2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>密码保护：近期发展计划</title>
		<link>http://www.cruelyouth.com/2012/01/15/%e8%bf%91%e6%9c%9f%e5%8f%91%e5%b1%95%e8%ae%a1%e5%88%92/</link>
		<comments>http://www.cruelyouth.com/2012/01/15/%e8%bf%91%e6%9c%9f%e5%8f%91%e5%b1%95%e8%ae%a1%e5%88%92/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 10:11:58 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=926</guid>
		<description><![CDATA[无法提供摘要。这是一篇受保护的文章。]]></description>
			<content:encoded><![CDATA[<form action="http://www.cruelyouth.com/wp-pass.php" method="post">
<p>这是一篇受密码保护的文章。您需要提供访问密码：</p>
<p><label for="pwbox-926">密码：<br />
<input name="post_password" id="pwbox-926" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="提交" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2012/01/15/%e8%bf%91%e6%9c%9f%e5%8f%91%e5%b1%95%e8%ae%a1%e5%88%92/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>密码保护：某日与麦总的倾谈</title>
		<link>http://www.cruelyouth.com/2012/01/09/%e6%9f%90%e6%97%a5%e4%b8%8e%e9%ba%a6%e6%80%bb%e7%9a%84%e5%80%be%e8%b0%88/</link>
		<comments>http://www.cruelyouth.com/2012/01/09/%e6%9f%90%e6%97%a5%e4%b8%8e%e9%ba%a6%e6%80%bb%e7%9a%84%e5%80%be%e8%b0%88/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 12:57:26 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=921</guid>
		<description><![CDATA[无法提供摘要。这是一篇受保护的文章。]]></description>
			<content:encoded><![CDATA[<form action="http://www.cruelyouth.com/wp-pass.php" method="post">
<p>这是一篇受密码保护的文章。您需要提供访问密码：</p>
<p><label for="pwbox-921">密码：<br />
<input name="post_password" id="pwbox-921" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="提交" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2012/01/09/%e6%9f%90%e6%97%a5%e4%b8%8e%e9%ba%a6%e6%80%bb%e7%9a%84%e5%80%be%e8%b0%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery plugin</title>
		<link>http://www.cruelyouth.com/2011/09/22/jquery-plugin/</link>
		<comments>http://www.cruelyouth.com/2011/09/22/jquery-plugin/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 06:42:10 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[Javascript/HTML5]]></category>
		<category><![CDATA[全部]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=879</guid>
		<description><![CDATA[http://docs.jquery.com/Plugins/Authoring]]></description>
			<content:encoded><![CDATA[<p>http://docs.jquery.com/Plugins/Authoring</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2011/09/22/jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVSegmentedControl</title>
		<link>http://www.cruelyouth.com/2011/07/24/svsegmentedcontrol/</link>
		<comments>http://www.cruelyouth.com/2011/07/24/svsegmentedcontrol/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 10:25:10 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[resources]]></category>
		<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=855</guid>
		<description><![CDATA[https://github.com/samvermette/SVSegmentedControl]]></description>
			<content:encoded><![CDATA[<p>https://github.com/samvermette/SVSegmentedControl</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2011/07/24/svsegmentedcontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>测试ifttt</title>
		<link>http://www.cruelyouth.com/2011/06/29/%e6%b5%8b%e8%af%95ifttt/</link>
		<comments>http://www.cruelyouth.com/2011/06/29/%e6%b5%8b%e8%af%95ifttt/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 06:52:39 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=821</guid>
		<description><![CDATA[如题]]></description>
			<content:encoded><![CDATA[<p>如题</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2011/06/29/%e6%b5%8b%e8%af%95ifttt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOW TO &#8211; 申请ios developer program license</title>
		<link>http://www.cruelyouth.com/2011/06/16/how-to-%e7%94%b3%e8%af%b7ios-developer-program-license/</link>
		<comments>http://www.cruelyouth.com/2011/06/16/how-to-%e7%94%b3%e8%af%b7ios-developer-program-license/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 09:47:22 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=790</guid>
		<description><![CDATA[http://www.cocoachina.com/bbs/read.php?tid-13372.html]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cocoachina.com/bbs/read.php?tid-13372.html">http://www.cocoachina.com/bbs/read.php?tid-13372.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2011/06/16/how-to-%e7%94%b3%e8%af%b7ios-developer-program-license/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cocos2d notes(5)</title>
		<link>http://www.cruelyouth.com/2011/06/15/cocos2d-notes5/</link>
		<comments>http://www.cruelyouth.com/2011/06/15/cocos2d-notes5/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 02:58:27 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=754</guid>
		<description><![CDATA[粒子效果 12345678910111213141516171819202122232425262728293031323334353637383940414243444546&#160; &#160; &#91;self removeChildByTag:1 cleanup:YES&#93;; &#160; &#160; &#160; &#160; CCParticleSystem* system; &#160; &#160; &#160; &#160; switch &#40;particleType&#41; &#160; &#160; &#123; &#160; &#160; &#160; &#160; case ParticleTypeExplosion: &#160; &#160; &#160; &#160; &#160; &#160; system = &#91;CCParticleExplosion node&#93;; &#160; &#160; &#160; &#160; &#160; &#160; break; &#160; &#160; &#160; &#160; case ParticleTypeFire: &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>粒子效果</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self removeChildByTag<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> cleanup<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CCParticleSystem<span style="color: #002200;">*</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>particleType<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeExplosion<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleExplosion node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeFire<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleFire node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeFireworks<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleFireworks node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeFlower<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleFlower node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeGalaxy<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleGalaxy node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeMeteor<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleMeteor node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeRain<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleRain node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeSmoke<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleSmoke node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeSnow<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleSnow node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeSpiral<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleSpiral node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeSun<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParticleSun node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">default</span><span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// do nothing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> tag<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>自定义粒子效果</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span><br />
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span><br />
<span style="color: #11740a; font-style: italic;">// Depending on the targeted device the ParticleEffectSelfMade class will either derive</span><br />
<span style="color: #11740a; font-style: italic;">// from CCPointParticleSystem or CCQuadParticleSystem</span><br />
<span style="color: #a61390;">@interface</span> ParticleEffectSelfMade <span style="color: #002200;">:</span> ARCH_OPTIMAL_PARTICLE_SYSTEM<br />
<span style="color: #002200;">&#123;</span><br />
<span style="color: #002200;">&#125;</span><br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>ARCH_OPTIMAL_PARTICLE_SYSTEM宏将自动判断使用效率较高的父类（CCPointParticleSystem or CCQuadParticleSystem）</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;ParticleEffectSelfMade.h&quot;</span><br />
<br />
<br />
<span style="color: #a61390;">@implementation</span> ParticleEffectSelfMade<br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self initWithTotalParticles<span style="color: #002200;">:</span><span style="color: #2400d9;">250</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithTotalParticles<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>numParticles<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithTotalParticles<span style="color: #002200;">:</span>numParticles<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// DURATION</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// most effects use infinite duration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.duration <span style="color: #002200;">=</span> kCCParticleDurationInfinity;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// for timed effects use a number in seconds how long particles should be emitted</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//self.duration = 2.0f;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// If the particle system runs for a fixed time, this will remove the particle system node from</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// its parent once all particles have died. Has no effect for infinite particle systems.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.autoRemoveOnFinish <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// MODE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// particles are affected by gravity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.emitterMode <span style="color: #002200;">=</span> kCCParticleModeGravity;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// particles move in a circle instead</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//self.emitterMode = kCCParticleModeRadius;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// some properties must only be used with a specific emitterMode!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.emitterMode <span style="color: #002200;">==</span> kCCParticleModeGravity<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// centerOfGravity is misleading as it determines the offset where particles appear. The actual</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// center of gravity is the node's position.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.centerOfGravity <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">15</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// gravity determines the particle's speed in the x and y directions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.gravity <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">50</span>, <span style="color: #002200;">-</span><span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// radial acceleration affects how fast particles move depending on their distance to the emitter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// positive radialAccel means particles speed up as they move away, negative means they slow down</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.radialAccel <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">90</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.radialAccelVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">20</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// tangential acceleration lets particles rotate around the emitter position, </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// and they speed up as they rotate around (slingshot effect)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.tangentialAccel <span style="color: #002200;">=</span> <span style="color: #2400d9;">120</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.tangentialAccelVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// speed is of course how fast particles move in general</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.speed <span style="color: #002200;">=</span> <span style="color: #2400d9;">15</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.speedVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.emitterMode <span style="color: #002200;">==</span> kCCParticleModeRadius<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// the distance from the emitter position that particles will be spawned and sent out</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// in a radial (circular) fashion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.startRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">100</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.startRadiusVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// the end radius the particles move towards, if less than startRadius particles will move</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// inwards, if greater than startRadius particles will move outward</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// you can use the keyword kCCParticleStartRadiusEqualToEndRadius to create a perfectly circular rotation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.endRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.endRadiusVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// how fast the particles rotate around</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rotatePerSecond <span style="color: #002200;">=</span> <span style="color: #2400d9;">180</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rotatePerSecondVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// EMITTER POSITION</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// emitter position is at the center of the node (default)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// this is where new particles will appear</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.position <span style="color: #002200;">=</span> CGPointZero;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.posVar <span style="color: #002200;">=</span> CGPointZero;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// The positionType determines if existing particles should be repositioned when the node is moving</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// (kCCPositionTypeGrouped) or if the particles should remain where they are (kCCPositionTypeFree).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.positionType <span style="color: #002200;">=</span> kCCPositionTypeFree;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// PARTICLE SIZE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// size of individual particles in pixels</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.startSize <span style="color: #002200;">=</span> 40.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.startSizeVar <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.endSize <span style="color: #002200;">=</span> kCCParticleStartSizeEqualToEndSize;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.endSizeVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// ANGLE (DIRECTION)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// the direction in which particles are emitted, 0 means upwards</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.angle <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.angleVar <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// PARTICLE LIFETIME</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// how long each individual particle will &quot;life&quot; (eg. stay on screen)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.life <span style="color: #002200;">=</span> 5.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; self.lifeVar <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// PARTICLE EMISSION RATE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// how many particles per second are created (emitted)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// particle creation stops if self.particleCount &gt;= self.totalParticles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// you can use this to create short burst effects with pauses between each burst</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.emissionRate <span style="color: #002200;">=</span> <span style="color: #2400d9;">30</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// normally set with initWithTotalParticles but you can change that number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.totalParticles <span style="color: #002200;">=</span> <span style="color: #2400d9;">250</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// PARTICLE COLOR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// A valid startColor must be set! Otherwise the particles may be invisible. The other colors are optional.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// These colors determine the color of the particle at the start and the end of its lifetime.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; startColor.r <span style="color: #002200;">=</span> 1.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColor.g <span style="color: #002200;">=</span> 0.25f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColor.b <span style="color: #002200;">=</span> 0.12f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColor.a <span style="color: #002200;">=</span> 1.0f;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColorVar.r <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColorVar.g <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColorVar.b <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; startColorVar.a <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; endColor.r <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; endColor.g <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; endColor.b <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; endColor.a <span style="color: #002200;">=</span> 1.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; endColorVar.r <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; endColorVar.g <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; endColorVar.b <span style="color: #002200;">=</span> 1.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; endColorVar.a <span style="color: #002200;">=</span> 0.0f;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// BLEND FUNC</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// blend func influences how transparent colors are calculated</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// the first parameter is for the source, the second for the target</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// available blend func parameters are:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// GL_ZERO &nbsp; GL_ONE &nbsp; GL_SRC_COLOR &nbsp; GL_ONE_MINUS_SRC_COLOR &nbsp; GL_SRC_ALPHA </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// GL_ONE_MINUS_SRC_ALPHA &nbsp; GL_DST_ALPHA &nbsp; GL_ONE_MINUS_DST_ALPHA</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.blendFunc <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>ccBlendFunc<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>GL_SRC_ALPHA, GL_DST_ALPHA<span style="color: #002200;">&#125;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// shortcut to set the blend func to: GL_SRC_ALPHA, GL_ONE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//self.blendAdditive = YES;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// PARTICLE TEXTURE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.texture <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCTextureCache sharedTextureCache<span style="color: #002200;">&#93;</span> addImage<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;fire.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> self;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>粒子设计工具<br />
<a href="http://particledesigner.71squared.com/">http://particledesigner.71squared.com/</a> <a href='http://www.cruelyouth.com/wp-content/uploads/2011/06/ParticleDesigner.zip'>下载ParticleDesigner</a></p>
<p>使用ParticleDesigner生成的效果</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> runEffect<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// remove any previous particle FX</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self removeChildByTag<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> cleanup<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CCParticleSystem<span style="color: #002200;">*</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>particleType<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeDesignedFX<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// by using ARCH_OPTIMAL_PARTICLE_SYSTEM either the CCQuadParticleSystem or CCPointParticleSystem class is</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// used depending on the current target.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;designed-fx.plist&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeDesignedFX2<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// uses a plist with the texture already embedded</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCQuadParticleSystem particleWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;designed-fx2.plist&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>.positionType <span style="color: #002200;">=</span> kCCPositionTypeFree;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeDesignedFX3<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// same effect but different texture (scaled down by Particle Designer)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCQuadParticleSystem particleWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;designed-fx3.plist&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>.positionType <span style="color: #002200;">=</span> kCCPositionTypeFree;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> ParticleTypeSelfMade<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ParticleEffectSelfMade node<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">default</span><span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// do nothing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; CGSize winSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span> winSize<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>.position <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>winSize.width <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>, winSize.height <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> tag<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>label setString<span style="color: #002200;">:</span>NSStringFromClass<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>在之前的射击游戏中加入爆炸粒子效果</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> gotHit<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; hitPoints<span style="color: #002200;">--</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>hitPoints &lt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; self.visible <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Play a particle effect when the enemy was destroyed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CCParticleSystem<span style="color: #002200;">*</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>type <span style="color: #002200;">==</span> EnemyTypeBoss<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;fx-explosion2.plist&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;fx-explosion.plist&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Set some parameters that can't be set in Particle Designer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>.positionType <span style="color: #002200;">=</span> kCCPositionTypeFree;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>.autoRemoveOnFinish <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a>.position <span style="color: #002200;">=</span> self.position;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Add the particle effect to the GameScene, for these reasons:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// - self is a sprite added to a spritebatch and will only allow CCSprite nodes (it crashes if you try)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// - self is now invisible which might affect rendering of the particle effect</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// - since the particle effects are short lived, there is no harm done by adding them directly to the GameScene</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>GameScene sharedGameScene<span style="color: #002200;">&#93;</span> addChild<span style="color: #002200;">:</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/system.html"><span style="color: #a61390;">system</span></a><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2011/06/15/cocos2d-notes5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocos2d notes(3)</title>
		<link>http://www.cruelyouth.com/2011/06/12/cocos2d-notes3/</link>
		<comments>http://www.cruelyouth.com/2011/06/12/cocos2d-notes3/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 11:31:08 +0000</pubDate>
		<dc:creator>Mars</dc:creator>
				<category><![CDATA[Cocos2D]]></category>
		<category><![CDATA[全部]]></category>

		<guid isPermaLink="false">http://www.cruelyouth.com/?p=715</guid>
		<description><![CDATA[Scene显示或被替换的3个重要事件 123456789101112131415161718-&#40;void&#41; onEnter &#123; &#160; &#160; &#160; &#160; // Called right after a node’s init method is called. &#160; &#160; &#160; &#160; // If using a CCTransitionScene: called when the transition begins. &#160; &#160; &#160; &#160; &#91;super onEnter&#93;; &#125; -&#40;void&#41; onEnterTransitionDidFinish &#123; &#160; &#160; &#160; &#160; // Called right after onEnter. &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Scene显示或被替换的3个重要事件</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> onEnter<br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Called right after a node’s init method is called. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// If using a CCTransitionScene: called when the transition begins. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super onEnter<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span> <br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> onEnterTransitionDidFinish<br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Called right after onEnter. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// If using a CCTransitionScene: called when the transition has ended. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super onEnterTransitionDidFinish<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span> <br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> onExit<br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Called right before node’s dealloc method is called. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// If using a CCTransitionScene: called when the transition has ended. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super onExit<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>Scene替换时发生的事件顺序</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">2011-06-12 19:35:39.374 ScenesAndLayers[21353:207] ===========================================<br />
2011-06-12 19:35:39.375 ScenesAndLayers[21353:207] scene: OtherScene<br />
2011-06-12 19:35:39.375 ScenesAndLayers[21353:207] init: &lt;OtherScene = 06465B40 | Tag = -1&gt;<br />
2011-06-12 19:35:44.743 ScenesAndLayers[21353:207] onEnter: &lt;OtherScene = 06465B40 | Tag = -1&gt;<br />
2011-06-12 19:35:47.760 ScenesAndLayers[21353:207] onExit: &lt;FirstScene = 0783AD30 | Tag = -1&gt;<br />
2011-06-12 19:35:47.761 ScenesAndLayers[21353:207] onEnterTransitionDidFinish: &lt;OtherScene = 06465B40 | Tag = -1&gt;<br />
2011-06-12 19:35:47.761 ScenesAndLayers[21353:207] dealloc: &lt;FirstScene = 0783AD30 | Tag = -1&gt;</div></td></tr></tbody></table></div>
<p>由此可知，在init后才发生onEnter，如果init初始化数据较多，就会导致画面tingdun，所以要加入loading scene</p>
<p>一个范例方法<br />
LoadScene.h</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">enum</span> <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; TargetSceneINVALID <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; TargetSceneFirstScene, <br />
&nbsp; &nbsp; &nbsp; &nbsp; TargetSceneOtherScene, <br />
&nbsp; &nbsp; &nbsp; &nbsp; TargetSceneMAX, <br />
<span style="color: #002200;">&#125;</span> TargetScenes; <br />
&nbsp;<br />
<span style="color: #11740a; font-style: italic;">// LoadingScene is derived directly from Scene. We don't need a CCLayer for this scene. </span><br />
<span style="color: #a61390;">@interface</span> LoadingScene <span style="color: #002200;">:</span> CCScene <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; TargetScenes targetScene_; <br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>LoadScene.m</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sceneWithTargetScene<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>TargetScenes<span style="color: #002200;">&#41;</span>targetScene; <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// This creates an autorelease object of the current class (self == &nbsp;</span><br />
LoadingScene<span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self alloc<span style="color: #002200;">&#93;</span> initWithTargetScene<span style="color: #002200;">:</span>targetScene<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithTargetScene<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>TargetScenes<span style="color: #002200;">&#41;</span>targetScene <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; targetScene_ <span style="color: #002200;">=</span> targetScene; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CCLabel<span style="color: #002200;">*</span> label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCLabel labelWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Loading ...&quot;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fontName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Marker Felt&quot;</span> fontSize<span style="color: #002200;">:</span><span style="color: #2400d9;">64</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGSize size <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span> winSize<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label.position <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>size.width <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>, size.height <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Must wait one frame before loading the target scene! </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self scheduleUpdate<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> self; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> update<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ccTime<span style="color: #002200;">&#41;</span>delta <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self unscheduleAllSelectors<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Decide which scene to load based on the TargetScenes enum. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>targetScene_<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> TargetSceneFirstScene<span style="color: #002200;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span> replaceScene<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>FirstScene scene<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> TargetSceneOtherScene<span style="color: #002200;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span> replaceScene<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>OtherScene scene<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">default</span><span style="color: #002200;">:</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Always warn if an unspecified enum value was used </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSAssert2<span style="color: #002200;">&#40;</span><span style="color: #a61390;">nil</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@: unsupported TargetScene %i&quot;</span>, &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NSStringFromSelector<span style="color: #002200;">&#40;</span>_cmd<span style="color: #002200;">&#41;</span>, targetScene_<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>为什么不能在LoadScene 的init方法中直接调用replaceScene<br />
原因1：永远不要在node的init中调用CCDirector的replaceScene方法<br />
原因2：这样调用会让app崩溃，因为无法在初始化（init)一个node的同时replace掉它</p>
<p>Singleton</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span>MultiLayerScene<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> sharedLayer <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; NSAssert<span style="color: #002200;">&#40;</span>multiLayerSceneInstance <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MultiLayerScene not available!&quot;</span><span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> multiLayerSceneInstance; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// MultiLayerScene will be deallocated now, you must set it to nil </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; multiLayerSceneInstance <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// don't forget to call &quot;super dealloc&quot; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>当一个Scene上有两个层重叠，如何判断哪个层接收touch事件<br />
假设UserInterfaceLayer* uiLayer 在GameLayer* gameLayer之上<br />
UserInterfacelayer.m</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> registerWithTouchDispatcher<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCTouchDispatcher sharedDispatcher<span style="color: #002200;">&#93;</span> addTargetedDelegate<span style="color: #002200;">:</span>self priority<span style="color: #002200;">:-</span><span style="color: #2400d9;">1</span> swallowsTouches<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// Implements logic to check if the touch location was in an area that this layer wants to handle as input.</span><br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span> isTouchForMe<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>touchLocation<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CCNode<span style="color: #002200;">*</span> node <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>UILayerTagFrameSprite<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> CGRectContainsPoint<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>node boundingBox<span style="color: #002200;">&#93;</span>, touchLocation<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> ccTouchBegan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITouch<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touch withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CGPoint location <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MultiLayerScene locationFromTouch<span style="color: #002200;">:</span>touch<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; bool isTouchHandled <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self isTouchForMe<span style="color: #002200;">:</span>location<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isTouchHandled<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Simply highlight the UI layer's sprite to show that it received the touch.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CCNode<span style="color: #002200;">*</span> node <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>UILayerTagFrameSprite<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; NSAssert<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>node isKindOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>CCSprite class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;node is not a CCSprite&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CCSprite<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>node<span style="color: #002200;">&#41;</span>.color <span style="color: #002200;">=</span> ccRED;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// 省略</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> isTouchHandled;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> ccTouchEnded<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITouch<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touch withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CCNode<span style="color: #002200;">*</span> node <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>UILayerTagFrameSprite<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; NSAssert<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>node isKindOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>CCSprite class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;node is not a CCSprite&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CCSprite<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>node<span style="color: #002200;">&#41;</span>.color <span style="color: #002200;">=</span> ccWHITE;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>在registerWithTouchDispatcher中将自己获取touch的优先级设为最高，然后在-(BOOL) ccTouchBegan:withEvent:中如果返回YES，这次的touch将被uiLayer吞掉（swallow)，如果返回NO，则由gameLayer继续处理。</p>
<p>使用CCMultiplexLayer在不同Layer间切换</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CCLayer<span style="color: #002200;">*</span> layer1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCLayer node<span style="color: #002200;">&#93;</span>; <br />
CCLayer<span style="color: #002200;">*</span> layer2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCLayer node<span style="color: #002200;">&#93;</span>; <br />
CCMultiplexLayer<span style="color: #002200;">*</span> mpLayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMultiplexLayer layerWithLayers<span style="color: #002200;">:</span>layer1, layer2, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>; <br />
<span style="color: #11740a; font-style: italic;">// Switches to layer2 but keeps layer1 as child of mpLayer.</span><br />
<span style="color: #002200;">&#91;</span>mpLayer switchTo<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>; <br />
<span style="color: #11740a; font-style: italic;">// Switches to layer1, removes layer2 from mpLayer and releases its memory.</span><br />
<span style="color: #11740a; font-style: italic;">// After this call you must not switch back to layer2 (index: 1) anymore!</span><br />
<span style="color: #002200;">&#91;</span>mpLayer switchToAndReleaseMe<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>CCColorLayer</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Set background color to magenta. The most unobtrusive color imaginable. </span><br />
CCColorLayer<span style="color: #002200;">*</span> colorLayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCColorLayer layerWithColor<span style="color: #002200;">:</span>ccc4<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">255</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>colorLayer z<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>Sprite Class</p>
<p>Spider.h</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@interface</span> Spider <span style="color: #002200;">:</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a> <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; CCSprite<span style="color: #002200;">*</span> spiderSprite; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> spiderWithParentNode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CCNode<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parentNode; <br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithParentNode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CCNode<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parentNode; <br />
&nbsp;<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Spider.m</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;Spider.h&quot; </span><br />
&nbsp;<br />
<span style="color: #a61390;">@implementation</span> Spider <br />
&nbsp;<br />
<span style="color: #11740a; font-style: italic;">// Static autorelease initializer, mimics cocos2d's memory allocation scheme. </span><br />
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> spiderWithParentNode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CCNode<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parentNode <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>self alloc<span style="color: #002200;">&#93;</span> initWithParentNode<span style="color: #002200;">:</span>parentNode<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithParentNode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CCNode<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parentNode <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGSize screenSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCDirector sharedDirector<span style="color: #002200;">&#93;</span> winSize<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spiderSprite <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;spider.png&quot;</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spiderSprite.position <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>CCRANDOM_0_1<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; screenSize.width, CCRANDOM_0_1<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> screenSize.height<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>parentNode addChild<span style="color: #002200;">:</span>spiderSprite<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Manually schedule update via the undocumented CCScheduler class. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCScheduler sharedScheduler<span style="color: #002200;">&#93;</span> scheduleUpdateForTarget<span style="color: #002200;">:</span>self priority<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;paused<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> self; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Must manually unschedule, it is not done automatically. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCScheduler sharedScheduler<span style="color: #002200;">&#93;</span> unscheduleUpdateForTarget<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>通过注册CCScheduler的 scheduleUpdateForTarget:priority:方法<br />
使Spider每帧调用update:方法</p>
<p>让Spider类实现CCTargetedTouchDelegate协议，使Spider类接收touch<br />
@interface Spider : NSObject <CCTargetedTouchDelegate><br />
{<br />
        …<br />
}<br />
修改后的Spider.m</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithParentNode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CCNode<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parentNode <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; …<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Manually schedule update via the undocumented CCScheduler class. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCScheduler sharedScheduler<span style="color: #002200;">&#93;</span> scheduleUpdateForTarget<span style="color: #002200;">:</span>self priority<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;paused<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Manually add this class as receiver of targeted touch events. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCTouchDispatcher sharedDispatcher<span style="color: #002200;">&#93;</span> addTargetedDelegate<span style="color: #002200;">:</span>self &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;priority<span style="color: #002200;">:-</span><span style="color: #2400d9;">1</span> swallowsTouches<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> self; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Must manually unschedule, it is not done automatically! </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCScheduler sharedScheduler<span style="color: #002200;">&#93;</span> unscheduleUpdateForTarget<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Must manually remove this class as touch input receiver! </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CCTouchDispatcher sharedDispatcher<span style="color: #002200;">&#93;</span> removeDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #11740a; font-style: italic;">// Extract common logic into a separate method accepting parameters. </span><br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> moveAway<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">float</span><span style="color: #002200;">&#41;</span>duration position<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>moveTo <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>spiderSprite stopAllActions<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; CCMoveBy<span style="color: #002200;">*</span> move <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMoveBy actionWithDuration<span style="color: #002200;">:</span>duration position<span style="color: #002200;">:</span>moveTo<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>spiderSprite runAction<span style="color: #002200;">:</span>move<span style="color: #002200;">&#93;</span>; <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> update<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ccTime<span style="color: #002200;">&#41;</span>delta <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; numUpdates<span style="color: #002200;">++</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>numUpdates &gt; <span style="color: #2400d9;">50</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numUpdates <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Move at regular speed. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGPoint moveTo <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>CCRANDOM_0_1<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">200</span> <span style="color: #002200;">-</span> <span style="color: #2400d9;">100</span>, &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CCRANDOM_0_1<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">100</span> <span style="color: #002200;">-</span> <span style="color: #2400d9;">50</span><span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self moveAway<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span> position<span style="color: #002200;">:</span>moveTo<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
<span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> ccTouchBegan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITouch <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touch withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event <br />
<span style="color: #002200;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Check if this touch is on the Spider's sprite. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CGPoint touchLocation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MultiLayerScene locationFromTouch<span style="color: #002200;">:</span>touch<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> isTouchHandled <span style="color: #002200;">=</span> CGRectContainsPoint<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>spiderSprite boundingBox<span style="color: #002200;">&#93;</span>, &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;touchLocation<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isTouchHandled<span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #11740a; font-style: italic;">// Reset move counter. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numUpdates <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Move away from touch loation rapidly. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CGPoint moveTo; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">float</span> moveDistance <span style="color: #002200;">=</span> <span style="color: #2400d9;">60</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">float</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/rand.html"><span style="color: #a61390;">rand</span></a> <span style="color: #002200;">=</span> CCRANDOM_0_1<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>; <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Randomly pick one of four corners to move away to. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/rand.html"><span style="color: #a61390;">rand</span></a> &lt; 0.25f<span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveTo <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>moveDistance, moveDistance<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/rand.html"><span style="color: #a61390;">rand</span></a> &lt; 0.5f<span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveTo <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span>moveDistance, moveDistance<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><a href="http://www.opengroup.org/onlinepubs/009695399/functions/rand.html"><span style="color: #a61390;">rand</span></a> &lt; 0.75f<span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveTo <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>moveDistance, <span style="color: #002200;">-</span>moveDistance<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveTo <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span>moveDistance, <span style="color: #002200;">-</span>moveDistance<span style="color: #002200;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Move quickly: </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self moveAway<span style="color: #002200;">:</span>0.1f position<span style="color: #002200;">:</span>moveTo<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> isTouchHandled; <br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>CCProgressTimer</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Progress timer is a sprite only partially displayed to visualize some kind of progress.</span><br />
CCProgressTimer<span style="color: #002200;">*</span> timer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCProgressTimer progressWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;firething.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
timer.type <span style="color: #002200;">=</span> kCCProgressTimerTypeRadialCCW;<br />
timer.percentage <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>timer z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> tag<span style="color: #002200;">:</span>UILayerTagProgressTimer<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #11740a; font-style: italic;">// The update is needed for the progress timer.</span><br />
<span style="color: #002200;">&#91;</span>self scheduleUpdate<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> update<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ccTime<span style="color: #002200;">&#41;</span>delta<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CCNode<span style="color: #002200;">*</span> node <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>UILayerTagProgressTimer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; NSAssert<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>node isKindOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>CCProgressTimer class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;node is not a CCProgressTimer&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Updates the progress timer</span><br />
&nbsp; &nbsp; CCProgressTimer<span style="color: #002200;">*</span> timer <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>CCProgressTimer<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>node;<br />
&nbsp; &nbsp; timer.percentage <span style="color: #002200;">+=</span> delta <span style="color: #002200;">*</span> <span style="color: #2400d9;">10</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>timer.percentage &gt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">100</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; timer.percentage <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>CCParallaxNode</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Load the sprites for each parallax layer, from background to foreground.</span><br />
CCSprite<span style="color: #002200;">*</span> para1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;parallax1.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
CCSprite<span style="color: #002200;">*</span> para2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;parallax2.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
CCSprite<span style="color: #002200;">*</span> para3 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;parallax3.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
CCSprite<span style="color: #002200;">*</span> para4 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;parallax4.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #11740a; font-style: italic;">// Set the correct offsets depending on the screen and image sizes.</span><br />
para1.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;<br />
para2.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;<br />
para3.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, 0.6f<span style="color: #002200;">&#41;</span>;<br />
para4.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;<br />
CGPoint topOffset <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, screenSize.height<span style="color: #002200;">&#41;</span>;<br />
CGPoint midOffset <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, screenSize.height <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;<br />
CGPoint downOffset <span style="color: #002200;">=</span> CGPointZero;<br />
<span style="color: #11740a; font-style: italic;">// Create a parallax node and add the sprites to it.</span><br />
CCParallaxNode<span style="color: #002200;">*</span> paraNode <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCParallaxNode node<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>paraNode addChild<span style="color: #002200;">:</span>para1 z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span> parallaxRatio<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span>0.5f, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> positionOffset<span style="color: #002200;">:</span>topOffset<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>paraNode addChild<span style="color: #002200;">:</span>para2 z<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span> parallaxRatio<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> positionOffset<span style="color: #002200;">:</span>topOffset<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>paraNode addChild<span style="color: #002200;">:</span>para3 z<span style="color: #002200;">:</span><span style="color: #2400d9;">4</span> parallaxRatio<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> positionOffset<span style="color: #002200;">:</span>midOffset<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>paraNode addChild<span style="color: #002200;">:</span>para4 z<span style="color: #002200;">:</span><span style="color: #2400d9;">3</span> parallaxRatio<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">3</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> positionOffset<span style="color: #002200;">:</span>downOffset<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>paraNode z<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> tag<span style="color: #002200;">:</span>ParallaxSceneTagParallaxNode<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #11740a; font-style: italic;">// Move the parallax node to show the parallaxing effect.</span><br />
CCMoveBy<span style="color: #002200;">*</span> move1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMoveBy actionWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">5</span> position<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
CCMoveBy<span style="color: #002200;">*</span> move2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMoveBy actionWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">15</span> position<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
CCSequence<span style="color: #002200;">*</span> sequence <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCSequence actions<span style="color: #002200;">:</span>move1, move2, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;<br />
CCRepeatForever<span style="color: #002200;">*</span> repeat <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCRepeatForever actionWithAction<span style="color: #002200;">:</span>sequence<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>paraNode runAction<span style="color: #002200;">:</span>repeat<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>CCRibbon</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:auto;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> resetRibbon<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Removes the ribbon and creates a new one.</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self removeChildByTag<span style="color: #002200;">:</span>ParallaxSceneTagRibbon cleanup<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; CCRibbon<span style="color: #002200;">*</span> ribbon <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCRibbon ribbonWithWidth<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span> image<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;spider.png&quot;</span> length<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span> color<span style="color: #002200;">:</span>ccc4<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">255</span><span style="color: #002200;">&#41;</span> fade<span style="color: #002200;">:</span>0.5f<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>ribbon z<span style="color: #002200;">:</span><span style="color: #2400d9;">5</span> tag<span style="color: #002200;">:</span>ParallaxSceneTagRibbon<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>CCRibbon<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> getRibbon<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CCNode<span style="color: #002200;">*</span> node <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getChildByTag<span style="color: #002200;">:</span>ParallaxSceneTagRibbon<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; NSAssert<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>node isKindOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>CCRibbon class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;node is not a CCRibbon&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span>CCRibbon<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>node;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> addRibbonPoint<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>point<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CCRibbon<span style="color: #002200;">*</span> ribbon <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getRibbon<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>ribbon addPointAt<span style="color: #002200;">:</span>point width<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> ccTouchBegan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITouch<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touch withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addRibbonPoint<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>MultiLayerScene locationFromTouch<span style="color: #002200;">:</span>touch<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> ccTouchMoved<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITouch<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touch withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addRibbonPoint<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>MultiLayerScene locationFromTouch<span style="color: #002200;">:</span>touch<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> ccTouchEnded<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITouch<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touch withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self resetRibbon<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>CCMotionStreak<br />
用来替换CCRibbon</p>
<div class="codecolorer-container objc geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> resetMotionStreak<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Removes the CCMotionStreak and creates a new one.</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self removeChildByTag<span style="color: #002200;">:</span>ParallaxSceneTagRibbon cleanup<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; CCMotionStreak<span style="color: #002200;">*</span> streak <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CCMotionStreak streakWithFade<span style="color: #002200;">:</span>0.7f minSeg<span style="color: #002200;">:</span><span style="color: #2400d9;">10</span><br />
&nbsp; &nbsp; image<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;spider.png&quot;</span> width<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span> length<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span> color<span style="color: #002200;">:</span>ccc4<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">255</span>, <span style="color: #2400d9;">255</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>streak z<span style="color: #002200;">:</span><span style="color: #2400d9;">5</span> tag<span style="color: #002200;">:</span>ParallaxSceneTagRibbon<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> addMotionStreakPoint<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGPoint<span style="color: #002200;">&#41;</span>point<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CCMotionStreak<span style="color: #002200;">*</span> streak <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self getMotionStreak<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>streak.ribbon addPointAt<span style="color: #002200;">:</span>point width<span style="color: #002200;">:</span><span style="color: #2400d9;">32</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cruelyouth.com/2011/06/12/cocos2d-notes3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

