cocos2d-x

Cocos2d-x设计模式发掘之一:单例模式

萝らか妹 提交于 2019-12-03 15:59:46
本系列文章我将和大家一起来发掘cocos2d-x中所使用到的设计模式,同样的,这些模式在cocos2d-iphone中也可以找到其身影。 声明 :这里发掘模式只是我的个人爱好,通过这个过程,我希望能加深自己对于设计模式运用的理解。关于模式的学习,市面上已经有许多非常好的书籍了。比如《Head First设计模式》、GoF的设计模式,还有《研磨设计模式》等。如果读者对于设计模式完全不了解的话,建议先阅读上面至少一本书籍,了解设计模式之后再阅读本系列文章。这样大家才会有相互交流的共同语言。 为什么要发掘设计模式呢?因为设计模式本身就是人们在一些面向对象的软件系统里面发掘出来的,在一定的场景之下可以重用的解决方案。通过对模式的挖掘,我可以借此机会学习一下这些优秀的设计思想。因为我觉得,一个好的开源游戏框架除了能给我们开发者带来开发效率的提升以外,还应该被我们吸收其设计思想,这样它的价值才能完整。 本系列文章将按照如下思路进行模式挖掘: – 找出某个设计模式的应用场景(类、类结构、对象结构,必要时结合UML类图) – 分析为什么要使用此模式(即设计决策) – 使用此模式的优缺点是什么(任何事务都有两面性,设计模式也不例外) – 此模式的定义及一般实现(这个在GoF的经典书籍里面有,这里借用一下) – 在游戏开发中如何运用此模式(自己对于模式运用场景的理解) – 此模式经常与哪些模式配合使用

Check If animation is running in cocos2d-x

纵饮孤独 提交于 2019-12-03 14:23:20
I am currently learning cocos2D-x and am doing some sprite animation. My Objective is that when a button is clicked the object moves to left with some animation. Now if you click multiple times rapidly the animation takes place immediately and it looks like the bear is hoping instead of walking. The solution to it looks simple that I should check if animation is already running and if running the new animation should not take place. The following is a part of my code. CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("AnimBear.plist"); CCSpriteBatchNode* spriteBatchNode =

Android JNI - Call function on Android UI thread from C++

梦想的初衷 提交于 2019-12-03 14:20:58
Our game engine Cocos2d-x runs natively on android on its own non-Java-UI-thread . We need to call certain Java functions from C++ via JNI on the Android UI thread . For calling JNI-Functions , we're using the JNIHelper.h/cpp from here (GitHub): JniHelper.h , JniHelper.cpp For example this C++ code: auto retVal = JniHelper::callStaticStringMethod("org/utils/Facebook", "getFacebookTokenString"); Ideally, we'd like to have all these calls happen on the Android UI thread and pass an std::function as a parameter which is called with the return value on the Cocos2d-x-thread again once the function

Fast Gaussian blur at pause [closed]

﹥>﹥吖頭↗ 提交于 2019-12-03 14:16:41
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. In cocos2d-x I need to implement fast gaussian blur and here is how it should looks like( I just found some game on the App Store with already done such blur, in unity): So, it's nice fadeIn - fadeOut blur when user pauses the game. GPUImage already has a fast blur I need, but I can't find solution for cocos2d-x. v1 code when it was (GPUImage v1) Objective C v2 code when is now Swift(GPUImage v2) Swift GPUImage-x C++

Android back button does not work

大兔子大兔子 提交于 2019-12-03 13:48:54
问题 I am using cocos2dx to make a small game and in the activity of my game i give the following functions to handle back button. @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return super.onKeyDown(keyCode, event); } @Override public void onDestroy() { android.os.Process.killProcess(android.os.Process.myPid()); super.onDestroy(); } On pressing back button i get the following warning in my logcat Can't open keycharmap file Error loading keycharmap file '/system/usr/keychars

"extensions/ExtensionMacros.h”: No such file 问题

随声附和 提交于 2019-12-03 13:19:26
今天在做2.x移植到3.1.1的时候候导入扩展包出现了错误,经过多方查找,最后终于把问题解决了,分享出来,给大家提供一个参考。 第一步,我们需要导入三个包,导入方式:解决方案(右键)-》添加-》现有项目 导入第一个libGUI.vcxproj (H:\mycompany\EditBoxTest\cocos2d\cocos\ui\proj.win32) 导入第二个libExtensions.vcxproj (H:\mycompany\EditBoxTest\cocos2d\extensions\proj.win32) 导入第三个libCocosStudio.vcxproj (H:\mycompany\EditBoxTest\cocos2d\cocos\editor-support\cocostudio\proj.win32) 导完之后,进行第二步。 第二步,要把我们导入的项目引用到我们的项目里,这也是出现那个问题的原因,, 在工程名上右键-》引用-》添加新引用 然后把我们新添加的项目前边的复选框,选上就行了 第三步为我们的项目添加包含目录 项目名右键-》属性-》C/C++-》附加包含目录-》编辑 填入一下内容 $(EngineRoot) $(EngineRoot)cocos $(EngineRoot)cocos\editor-support 最后,编译一下,就没有那个错误了 备注

How to swap the sprite in the CCSprite object in Cocos2d-X

早过忘川 提交于 2019-12-03 12:16:35
I have an object that inherited from CCSprite. I want from inside this object to change the image. How do I change the image (sprite) without creating a new CCSprite object in Cocos2d-X? Thanks, Adrian. mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png")); No need to alter your custom class.. Hope this helps.. :) Works for me: mySprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("frame_name")); Before you need to load you sprites in cache: CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sprite_atlas

cocos2d-x android 移植 问题

大兔子大兔子 提交于 2019-12-03 10:50:46
由于android系统目前没有将boost加入,这里面使用了大量的STL及C++的一些语言特性,导致编译出现令人非常头痛的问题。 1、出现类似的异常函数错误 boost/exception/detail/exception_ptr.hpp:382: error: expected ';' before 'catch' boost/exception/detail/exception_ptr.hpp:387: error: expected primary-expression before 'catch boost/date_time/constrained_value.hpp:110: error: invalid initialization of reference of type 'const std::exception&' from expression of type 'boost::CV::simple_exception_policy<short unsigned int, 1u, 366u, boost::gregorian::bad_day_of_year>::exception_wrapper' boost/throw_exception.hpp:48: error: in passing argument 1 of 'void boost::throw

cocos2d-x工程中,让xcode4.6能够使用C++11标准库

冷暖自知 提交于 2019-12-03 10:21:23
在Cocos2d-x的开发中,如果你使用的xcode4.6,有时候希望使用C++11标准库的东西,比如 std::array,如果直接, # include <array> 将会出现无法找到array的问题。 这个时候我们就要对我们的xcode进行一下简单的配置。 在Building Settings里面,首先点击All, 然后在"Apple LLVM Compiler 4.2 - Language"区域: 设置 "C++ Language Dialect" 选项为 "c11" 设置 "C++ Standard Library" 选项为 "libc++ (LLVM standard C++ library with C++11 support)" 更多详细,请参见screenshot. 引用自stackoverflow Howard Hinnant's answer (with corrections) is the correct answer for the command line. To use the new C++11 standard library inside of Xcode: In the Build Settings tab for your project, scroll down to "Apple LLVM Compiler 4.1 >-

Windows Phone 8开发环境搭建

有些话、适合烂在心里 提交于 2019-12-03 09:53:23
开发Windows Phone需要两个工具:Windows Phone SDK 8.0和Visual Studio集成开发工具。我们购买的Visual Studio Ultimate 2012不包括Windows Phone SDK,由于Visual Studio Ultimate 2012是收费软件,如果广大读者没有授权,也可以使用Visual Studio Express 2012 for Windows Phone 8。 我们推荐的做法是如果有Visual Studio Ultimate 2012版本,先安装Visual Studio Ultimate 2012,再安装Windows Phone SDK。如果没有Visual Studio Ultimate 2012版本,直接下载Visual Studio Express 2012 for Windows Phone 8安装,Visual Studio Express 2012 for Windows Phone 8环境中包含了Windows Phone SDK 8.0。 Windows Phone SDK 8.0安装 Windows Phone SDK 8.0的下载地址是http://www.microsoft.com/zh-cn/download/details.aspx?id=35471,在浏览器中打开该网址,如图所示