cocos2d-x

【深入Cocos2d-x】使用MVC架构搭建游戏Four

半城伤御伤魂 提交于 2019-12-09 20:39:00
喜欢Four这个项目,就赶快在 GitHub 上Star这个项目吧! 喜欢我的文章,来微博关注我吧: 王选易在学C艹 点我下载 ## 项目起源 项目Logo: 下面是该游戏的项目地址,各位想参考源代码的同学可以到我的GitHub上下载该项目的源码。 项目主页 GitHub地址 bug反馈及建议 我做这个项目的原始目的是实验MVC在游戏中的应用。 Model-View-Controller(MVC) 是一种组合设计模式,它体现了一种 关注点分离(Separation of concerns,SoC) 的思想。MVC主要把逻辑层和表现层进行了解耦,将一个问题划分成了不同的关注点。增强了应用的稳定性,易修改性和易复用性。 MVC经常被使用在Web框架中,包括J2EE,RoR和.Net中都对MVC模型进行了框架层面上的封装,以便程序员可以简单方便地作出结构良好的Web应用。 Cocos2d-x本身并没有提供内置的MVC支持,但是,我们还是可以在游戏中基于MVC架构来设计游戏。在这篇博文中,我将向大家展示一下我是如何使用MVC架构来塔尖 Four 这个游戏的。 ## 游戏情景 Four这个游戏的创意来自一个叫做走四棋的传统游戏,走四棋规则的详细介绍在这里: 走四棋的百度百科 。 下面我简单谈一下这个面板游戏(board game)的一些特性 一个4行4列的棋盘(Game Board)

Cocos2d-x中关于lua的坑

若如初见. 提交于 2019-12-09 19:17:43
上周在项目开发中遇到一个奇怪的问题,某个c++模块解压完的字节流数据传递给lua后,lua在做基于字节流的反序列化时始终出错,刚开始以为是不是c++模块读取出来的字节流有问题,但是debug发现,c++拿到的字节流确实是正确的,于是跑到lua的接口中打印了字节流的内容和长度发现,在某些情况下C++中打印出来的字节流和lua拿到的字节流的长度不等,突然想起可能是lua和C++对string的支持不同导致的.因为C++中没有字节这个类型,所以存储字节流就一般存储到以char类型结构为基础类型的数组或者std::string中,但是这时,如果对char数组或者std::string进行strlen类似的操作,则会存在隐患,因为strlen认为遇到'\0'字节就结束了,而如果存储在char数组中的字节流恰好是中间含有'\0'这个字节的话,则得出来的长度就有问题了;但是在lua中,string中含有'\0'是不会有问题的, 因为它求长度并不是简单的调用strlen,而是lua自己实现了strlen函数, 所以即使是拿到含有'\0'字符的字节流字符串, 也不会出现错误. 进过调试,发现确实是这里的问题,于是更改了cocos2d-x中 CCLuaStack中pushCCLuaValue函数中的代码即解决了上述问题,代码如下(注意注释的部分, 被注释的部分为cocos2d-x原来的代码):

ld: symbol(s) not found for architecture i386

做~自己de王妃 提交于 2019-12-09 16:28:27
#问题引出 ##在使用xcode运行cocos2d-x应用的时候发现出了这样的错误: Ld /Users/sjbwybls/Library/Developer/Xcode/DerivedData/MyGame-arludletzetwkseytsepwlnpmgtv/Build/Products/Debug-iphonesimulator/MyGame.app/MyGame normal i386 cd /Users/sjbwybls/cocos2d-x-2.1.4/projects/MyGame/proj.ios setenv IPHONEOS_DEPLOYMENT_TARGET 4.0 setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386

quick-2.x.x触摸管理机制

偶尔善良 提交于 2019-12-09 13:38:01
lua 代码写起来真的很快,项目开发速度要快不少;开始用quick也快半年了,一直在赶项目内容;也没怎么花时间去看quick-2.x.x和cocos2d-x-2.x.x有什么区别……; 今天碰到一个touch事件问题,被quick坑了;其实也不是什么大问题,就是触摸优先级的事; 因为cocos2d-x 2.x版本和3.x版本都有用过,然后也大概的看了下quick的实现,但是没有注意优先级的设定; 刚开始碰到问题时,一直以为quick-2.2.6应该和cocos2d-x 2.x版本的机制一样,按照这个思路一直实现不了; 最后问身边的同时,说他们做相似功能是都是按照对象层级来处……;详细查看了quick 的CCScene代码后还正是发现“sortAllTouchableNodes”这个方法,就是drawOrder来排序的; 然后,重新查看下lua代码,调整drawOrder后,问题就解决了…… 来源: oschina 链接: https://my.oschina.net/u/146011/blog/390623

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

自闭症网瘾萝莉.ら 提交于 2019-12-09 09:14:07
问题 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. 回答1: mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png")); No need to alter your custom class.. Hope this helps.. :) 回答2: Works for me: mySprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("frame_name")); Before you need to

Google Game Service Leaderboard can't show after submit score on Cocos2d-x Android?

荒凉一梦 提交于 2019-12-08 13:33:06
问题 I implement Google Game Service for Android (Cocos2d-x) with Cocos Helper of Sonar System Team. Everything is OK: Sign-In Google Game Service. Show Achievement and increateAchievement very good. The first time, I sign-in to Google Game Service ==> show leaderboard is OK. However, I submit score to leaderboard then re-show leaderboard again it always close automatic and I get respondCode=RESULT_RECONNECT_REQUIRED . Can you give me some suggestion to fix it ? 回答1: I've found answer: Reason of

CCCallFunc::create(this, callfunc_selector(Wack_ModeSelection::ParticleAnimation)); this callback showing error in cocos2d 3.0

百般思念 提交于 2019-12-08 12:54:23
问题 Please give the alternate of FiniteTimeAction* callFunc=CCCallFunc::create(this,callfunc_selector(Wack_ModeSelection::ParticleAnimation)); error : Static_cast from 'void' (Wack_ModeSelection::*)(CCObject )to cocos2d::SEL_Callfunc (aka void(cocos2d::Ref:: (()) is not allowed 来源: https://stackoverflow.com/questions/34527815/cccallfunccreatethis-callfunc-selectorwack-modeselectionparticleanimation

Cocos2dx Box2D - b2body GetUserData always returns null

我的未来我决定 提交于 2019-12-08 09:09:06
问题 am having one car and one bike object. at the time of collison detction. i need to get which(Car or bike) is colliding with wall. for that am using body->getuserdata . but it always returns null. am confuse d that why am getting null. were am wrong? i refer this link but same as i did. not useful. Code for car:- sprintf(temp,CAR_BODY_CAR_PLIST); m_Texture[2] = new TextureObject(temp,spritesheet1,1,true,kTexture2DPixelFormat_Default,2); // add cart // b2BodyDef bodyDef; b2FixtureDef fixtureDef

How to add vibration to cocos2d-x 3.2 on Android and iOS devices?

余生长醉 提交于 2019-12-08 07:54:50
问题 I want to vibrate my device in one of my slider functionality, using cocos2d-x 3.2. I followed some of reference links regarding this on the official forums but I'm still stumped. Can anyone help me? 回答1: After Searching a lot , Finally i am done with my Vibrate Function in Cocos2d-x 3.2 for android. There is one Vibrator Class. Vibrator.h #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include <jni.h> #include <android/log.h> #include "platform/android/jni/JniHelper.h" #endif #define CLASS