转载自
【黑米GameDev街区】
原文链接:
http://www.himigame.com/iphone-cocos2dx/603.html<wbr><div><br></div> <div><br></div> <div> <p style="line-height:25px; font-family:Arial; margin-top:0px; margin-bottom:0px"> <br></p> <p style="line-height:25px; font-family:Arial; margin-top:0px; margin-bottom:0px"> </p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 不得不说要说总结,因为Cocos2d-X的代码和Cocos2d-iphone两个引擎除了语言不同外(Cocos2d-X使用C++,Cocos2d-iphone使用Object-C)可以说没有其他差异=。 =</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 下面Himi举例对比几段代码来说明吧:</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <span style="font-size:16px"><strong> </strong></span><span style="font-size:16px"><span style="color:#ff00">创建添加一个精灵代码对比:</span></span></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <strong> 使用Cocos2d-X:</strong></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> </p> <div style="margin:18px 0px; width:1192px; line-height:25px; padding-top:1px; font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; overflow-x:auto; overflow-y:auto"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; color:silver; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:9px; border-left-color:rgb(108,226,108); border-left-width:3px; border-left-style:solid; background-color:rgb(248,248,248)"> <strong>[cpp]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit"> view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit">copy</a> <div style="left:380px; top:723px; width:17px; height:17px; position:absolute; z-index:99"> </div> </div> </div> <ol start="1" style="color:rgb(92,92,92); margin-top:0px!important; margin-bottom:1px!important; margin-left:45px!important"> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//---------Cocos2d-X代码部分--</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> <span style="color:#0820; margin:0px; padding:0px; background-color:inherit"> //创建一个精灵</span><span style="margin:0px; padding:0px; background-color:inherit"> </span> </span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> CCSprite *spriteTemp =CCSprite::spriteWithFile(<span style="color:blue; margin:0px; padding:0px; background-color:inherit">"icon.png"</span><span style="margin:0px; padding:0px; background-color:inherit">); </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> <span style="color:#0820; margin:0px; padding:0px; background-color:inherit"> //设置精灵的坐标</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> spriteTemp->setPosition(ccp(size.width*0.5,size.height*0.5)); </span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> <span style="color:#0820; margin:0px; padding:0px; background-color:inherit"> //将精灵添加到layer中</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> <span style="color:#06699; margin:0px; padding:0px; font-weight:bold; background-color:inherit"> this</span><span style="margin:0px; padding:0px; background-color:inherit">->addChild(spriteTemp,1); </span></span> </li> </ol> </div> <p style="line-height:25px; font-family:Arial; margin-top:0px; margin-bottom:0px"> </p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <strong>使用Cocos2d-iphone: </strong><br></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> </p> <div style="margin:18px 0px; width:1192px; line-height:25px; padding-top:1px; font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; overflow-x:auto; overflow-y:auto"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; color:silver; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:9px; border-left-color:rgb(108,226,108); border-left-width:3px; border-left-style:solid; background-color:rgb(248,248,248)"> <strong>[cpp]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit"> view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit">copy</a> <div style="left:380px; top:964px; width:17px; height:17px; position:absolute; z-index:99"> </div> </div> </div> <ol start="1" style="color:rgb(92,92,92); margin-top:0px!important; margin-bottom:1px!important; margin-left:45px!important"> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//---------Cocos2d-iphone代码部分--</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//创建一个精灵</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit">CCSprite *spriteTemp =[CCSprite spriteWithFile:@<span style="color:blue; margin:0px; padding:0px; background-color:inherit">"icon.png"</span><span style="margin:0px; padding:0px; background-color:inherit">]; </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//设置精灵的坐标</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit">spriteTemp.position=ccp(size.width*0.5,size.height*0.5); </span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//将精灵添加到layer中</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit">[self addChild:spriteTemp z:0 tag:1]; </span> </li> </ol> </div> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <br></p> <br style="line-height:25px; font-family:Arial"><p style="line-height:25px; font-family:Arial; margin-top:0px; margin-bottom:0px"> <span style="font-size:16px"><span style="color:#ff00">添加一个粒子代码对比:</span></span></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <span style="font-size:13px"></span></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; font-weight:bold; margin-top:4px; margin-bottom:4px"> </p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <span style="font-size:13px"><strong> 使用Cocos2d-X: </strong></span></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; font-weight:bold; margin-top:4px; margin-bottom:4px"> </p> <div style="margin:18px 0px; width:1192px; line-height:25px; padding-top:1px; font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; overflow-x:auto; overflow-y:auto"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; color:silver; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:9px; border-left-color:rgb(108,226,108); border-left-width:3px; border-left-style:solid; background-color:rgb(248,248,248)"> <strong>[cpp]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit"> view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit">copy</a> <div style="left:380px; top:1302px; width:17px; height:17px; position:absolute; z-index:99"> </div> </div> </div> <ol start="1" style="color:rgb(92,92,92); margin-top:0px!important; margin-bottom:1px!important; margin-left:45px!important"> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//---------Cocos2d-X代码部分-- </span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> CCParticleSystem *tempSystem =ARCH_OPTIMAL_PARTICLE_SYSTEM::particleWithFile(<span style="color:blue; margin:0px; padding:0px; background-color:inherit">"himi.plist"</span><span style="margin:0px; padding:0px; background-color:inherit">); </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> tempSystem->setPosition(ccp(100,100)); </span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"> <span style="color:#06699; margin:0px; padding:0px; font-weight:bold; background-color:inherit"> this</span><span style="margin:0px; padding:0px; background-color:inherit">->addChild(tempSystem); </span></span> </li> </ol> </div> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <strong> 使用Cocos2d-iphone:</strong></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> </p> <div style="margin:18px 0px; width:1192px; line-height:25px; padding-top:1px; font-family:Consolas,'Courier New',Courier,mono,serif; font-size:12px; overflow-x:auto; overflow-y:auto"> <div style="padding-left:45px"> <div style="padding:3px 8px 10px 10px; color:silver; line-height:normal; font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-size:9px; border-left-color:rgb(108,226,108); border-left-width:3px; border-left-style:solid; background-color:rgb(248,248,248)"> <strong>[cpp]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit"> view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/xiaominghimi/article/details/6938675#" rel="nofollow" style="margin:0px 10px 0px 0px; padding:1px; width:16px; height:16px; color:rgb(160,160,160); text-indent:-2000px; font-size:9px; text-decoration:none; display:inline-block; background-color:inherit">copy</a> <div style="left:380px; top:1483px; width:17px; height:17px; position:absolute; z-index:99"> </div> </div> </div> <ol start="1" style="color:rgb(92,92,92); margin-top:0px!important; margin-bottom:1px!important; margin-left:45px!important"> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit"><span style="color:#0820; margin:0px; padding:0px; background-color:inherit">//---------Cocos2d-iphone代码部分--</span><span style="margin:0px; padding:0px; background-color:inherit"> </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit">CCParticleSystem *tempSystem =[ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@<span style="color:blue; margin:0px; padding:0px; background-color:inherit">"himi.plist"</span><span style="margin:0px; padding:0px; background-color:inherit">]; </span></span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; color:inherit; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important"> <span style="color:black; margin:0px; padding:0px; background-color:inherit">tempSystem.position=ccp(100,100); </span> </li> <li style="border-style:none none none solid; margin:0px; padding:0px 3px 0px 10px!important; line-height:20px; border-left-color:rgb(108,226,108); border-left-width:3px; list-style-type:decimal-leading-zero; list-style-position:outside!important; background-color:rgb(248,248,248)"> <span style="color:black; margin:0px; padding:0px; background-color:inherit">[self addChild:tempSystem]; </span> </li> </ol> </div> <br style="line-height:25px; font-family:Arial"><br style="line-height:25px; font-family:Arial"><span style="font-family:Arial; line-height:25px"> 通过以上随便举例的两段代码童鞋们很清楚的看出来,基本上没有差异。</span> <p style="line-height:25px; font-family:Arial; margin-top:0px; margin-bottom:0px"> </p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <strong>这里还有三点要说下:</strong></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> </p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 第一:现在很多游戏公司都趋向于Cocos2d-X引擎开发游戏的趋势,不得不说Cocos2d-X多平台平移确实很诱惑人,而且通过网龙《91部落》手机网游的成功发布,不得不说Cocos2d-X已成熟!</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 第二:不少童鞋肯定会很想知道Cocos2d-X能多平台平移,那么平移稳定性如何?</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 通过Himi的了解,Cocos2d-X开发都会使用统一的C++语言开发,例如在iOS开发中使用Xcode+cocos2d-X,在Android上一般使用Eclipse+Android NDK+ADT....</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <span style="color:#ff00">其实总结一句,Cocos2d-iphone并不像很多童鞋认为的只要的一人开发就可打包多平台包这样子~ 如果说用一句话更贴切的形容Cocos2d-X,Himi会用“Cocos2d-X代码通用”来形容;</span></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <strong>从CC(CocoChina)上我看到王哲<span style="font-family:Arial,Helvetica,sans-serif; line-height:20px">walzer</span>(cocos2d-x 游戏引擎作者)在回复一童鞋问题时候这么说的:</strong></p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 问:关于如何打包cocos2d-x程序的问题 本人新手,想请教一下如何将Cocos2d-x win32的程序打包成iphone能够运行的程序,请各位大大不吝赐教!谢谢!</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> <strong>王哲<span style="font-family:Arial,Helvetica,sans-serif; line-height:20px">walzer</span></strong> 答:win32上只是让你调试方便,要发布到appstore上,你还是得有个mac机,装好cocos2d-x template,新建工程,然后把win32上代码拷过来,手工地加入xcode工程里面,编译运行</p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> </p> <p style="line-height:25px; padding-top:2px; padding-bottom:2px; font-family:Arial; margin-top:4px; margin-bottom:4px"> 从上面的对话可以证实Himi所说的Cocos2d-X是代码通用! OK,不多说了,大概就说这几点吧,继续忙了~</p> </div> </wbr>
cocos2d-x 和cocos2d-phone
最新推荐文章于 2024-08-16 23:20:20 发布