摘要:先看一段代码: 测试: 1: 输出 function: 0x7f0d0884ae00 test in onTouch 2: print(handler(c,c.onTouch)) print((function()c.onTouch(c)end)) 输出 function: 0x7f44d8d2ab
阅读全文
摘要:实现类似翻扑克牌的效果代码如下: OrbitCamera* rotate1; OrbitCamera* rotate2; if(towardRight){//向右翻转 rotate1=OrbitCamera::create(0.4f,1,...
阅读全文
摘要:写了一个方法,在onCreate和onResume中调用即可,4.4以上可用。private void openImmersiveMode() { if (android.os.Build.VERSION.SDK_INT > 18) { Window window...
阅读全文
摘要:由于c++的随机数其实是用了一张随机表,所以不是真正意义上的随机,cocos2dx中操作的时候会发现每次重新获取都会得到同样的值,那么解决办法采用置随机数种子,利用时间函数(时间唯一性),操作如下srand(int(time(0))+ rand());//置随机数种子int ran=CCRANDOM...
阅读全文
摘要:1.导入一个新项目步奏:解决方案:右键->添加->添加现有项目->添加依赖项目libCocoStudioD:\work\CannonDefender\cocos2d\cocos\editor-support\cocostudio\proj.win32添加依赖项目libExtensionsD:\wor...
阅读全文
摘要:GameEvent.h: 1 #pragma once 2 #include "cocos2d.h" 3 USING_NS_CC; 4 5 class GameEvent { 6 public: 7 //封装派发数据 8 static void dispatchSet(std::s...
阅读全文
摘要:1 if (sp1->boundingBox().intersectsRect(sp2->boundingBox())) {2 pLabel->setString(“碰撞飞机爆炸”);3 }else4 pLabel->setString(“~还没有碰撞·~”);5 6 }
阅读全文
摘要:cocos2dx自带的几种封装好的粒子系统,下面做个简单使用演示。ParticleFire火焰粒子系统ParticleFireworks烟花粒子系统ParticleSun太阳粒子系统ParticleGalaxy星系粒子系统ParticleFlower开花粒子系统ParticleMeteor流星粒子系...
阅读全文
摘要:返回time_t,即从1970年1月1日至今的秒数time_t getSysTime(){ time_t currentTime = time(NULL); return currentTime;}
阅读全文
摘要:#include int random(int start, int end) { //return start+rand()%(end-start+1); static std::random_device rd; static std::default_random_engin...
阅读全文
摘要:/*将originStr字符串中的searchStr替换成replaceStr*/std::string str_replace(std::string originStr,std::string searchStr,std::string replaceStr){ std::string::...
阅读全文
摘要:使用plist文件,优点方便做多国语言支持~也不用去做编码转换1.Resource目录下新建text.plist文件,内容格式如下 clickHurt 点击伤害 2.调用如下代码std::string chineseStr;Value...
阅读全文
摘要:1.首先头文件定义事件处理的函数原型private: bool onTouchBegan(Touch* tTouch,Event* eEvent);//手指按下事件 void onTouchMoved(Touch* tTouch,Event* eEvent);//手指移动事件 void onTouc...
阅读全文
摘要:简单记录一下2dx的鼠标交互事件。以及精灵绑定盒的点击判定Layer 子类的 init方法中:auto listener = EventListenerTouchOneByOne::create();// listener->onTouchBegan = CC_CALLBACK_2(GameMenu...
阅读全文
摘要:九宫格Sprite:itemBg = Scale9Sprite::create("pop/achieve_itembg.png");if(!itemBg)return false;itemBg->setAnchorPoint(Vec2::ANCHOR_MIDDLE);itemBg->setConte...
阅读全文
摘要:原因:cocos2dx的bug解决办法:放到action中,前面添加一个DelayTime延迟,代码如下this->runAction(Sequence::create(DelayTime::create(0.1f),CallFuncN::create([&](Node* pNode){pNode-...
阅读全文