接上一节内容:cocos2dx - 生成怪物及AI

本节主要讲如何通过创建简单的矩形区域来造成伤害

  在小游戏中简单的碰撞需求应用box2d等引擎会显得过于臃肿复杂,且功能不是根据需求定制,还要封装,为此本节讲述一下如何自己实现简单的碰撞,来达到伤害效果。

这里先看下效果图:

一、定义小组类别

  定义如下:

  1. // 组别mask
  2. enum enGroupMask
  3. {
  4. GROUP_NONE = 0x0000,
  5. GROUP_PLAYER = 0x0001,
  6. GROUP_MONSTER = 0x0002,
  7. };

  用二进制位来定义小组,方便后面判断用位快速判断。

二、定义CBody类用于碰撞实现

  代码如下:

  1. #ifndef __CBody_H__
  2. #define __CBody_H__
  3. #include "IGameDef.h"
  4. #include "cocos2d.h"
  5. #define DRAW_BODY 1
  6. #ifdef DRAW_BODY
  7. #include "GLES-Render.h"
  8. #endif
  9.  
  10. USING_NS_CC;
  11. class CBody : public Node
  12. {
  13. public:
  14. // implement the "static create()" method manually
  15. CREATE_FUNC(CBody);
  16.  
  17. virtual bool init();
  18.  
  19. void SetRect(float x, float y, float w, float h){ m_cRect = Rect(x,y,w,h); }
  20.  
  21. void SetGroupMask(enGroupMask nGroupMask){ m_nGroupMask = nGroupMask; }
  22.  
  23. enGroupMask GetGroupMask() const{ return m_nGroupMask; }
  24.  
  25. enGroupMask CanContactGroup() const;
  26.  
  27. //判断是否可以碰撞该类别
  28. bool IsGroupCanContact(enGroupMask nGroupMask) const;
  29.  
  30. const Rect GetRect() const;
  31.  
  32. //判断矩形是否交叉
  33. bool IntersectsRect(const Rect& rect) const;
  34.  
  35. void SetContactCallback(const std::function<void(CBody*)>& callback){ m_constactFunc = callback; }
  36.  
  37. // 碰撞回调函数
  38. void OnContact(CBody* pBody);
  39.  
  40. // 绘制矩形区域
  41. #ifdef DRAW_BODY
  42. virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags);
  43. virtual void onDraw(const Mat4 &transform, uint32_t flags);
  44. #endif
  45.  
  46. private:
  47.  
  48. CBody();
  49. ~CBody();
  50.  
  51. #ifdef DRAW_BODY
  52. CustomCommand m_pCustomCommand;
  53. b2Draw* m_debugDraw;
  54. #endif
  55.  
  56. Rect m_cRect;
  57.  
  58. std::function<void(CBody*)> m_constactFunc;
  59.  
  60. enGroupMask m_nGroupMask;
  61. };
  62.  
  63. #endif __CBody_H__

关键实现有以下几个:

  1、用位快速判断是否可以产生碰撞

  1. bool CBody::IsGroupCanContact(enGroupMask nGroupMask) const
  2. {
  3. return nGroupMask&CanContactGroup();
  4. }

  2、获取矩形实际的坐标,利用cocos2dx矩形相交判断方法,判断重叠

  1. const Rect CBody::GetRect() const
  2. {
  3. const Vec2& pt =this->convertToWorldSpace(this->getPosition());
  4. return Rect(pt.x + m_cRect.origin.x, pt.y + m_cRect.origin.y, m_cRect.size.width, m_cRect.size.height);
  5. }
  6.  
  7. bool CBody::IntersectsRect(const Rect& rect) const
  8. {
  9. return GetRect().intersectsRect(rect);
  10. }

  3、将创建的CBody类添加到管理中vector的实例m_vBody管理

  1. CBody::~CBody()
  2. {
  3. CBattleMgr::getInstance()->EreaseBody(this);
  4. #ifdef DRAW_BODY
  5. if (m_debugDraw)
  6. {
  7. delete m_debugDraw;
  8. m_debugDraw = NULL;
  9. }
  10. #endif
  11. }
  12.  
  13. bool CBody::init()
  14. {
  15. #ifdef DRAW_BODY
  16. m_debugDraw = new GLESDebugDraw(1.0);
  17. #endif
  18. CBattleMgr::getInstance()->InsertBody(this);
  19. return true;
  20. }

  同时每帧在管理类中的update进行碰撞判断如下:

  1. void CBattleMgr::update(float dt)
  2. {
  3. while (m_vBody.size()>)
  4. {
  5. size_t nLast = m_vBody.size() - ;
  6. CBody* pBody = m_vBody[nLast];
  7. m_vBody.pop_back();
  8. if (pBody)
  9. {
  10. m_vSwapBody.push_back(pBody);
  11. for (size_t i = ; i < nLast; ++i)
  12. {
  13. CBody* pTempBody = m_vBody[i];
  14. if (pTempBody )
  15. {
  16. bool hurt1 = pTempBody->IsGroupCanContact(pBody->GetGroupMask());
  17. bool hurt2 = pBody->IsGroupCanContact(pTempBody->GetGroupMask());
  18. if ((hurt1 || hurt2)&&pTempBody->IntersectsRect(pBody->GetRect()))
  19. {
  20. if (hurt1)
  21. {
  22. pTempBody->OnContact(pBody);
  23. }
  24. if (hurt2)
  25. {
  26. pBody->OnContact(pTempBody);
  27. }
  28. }
  29. }
  30. }
  31. }
  32. }
  33. m_vSwapBody.swap(m_vBody);
  34. }

  上述代码通过2个vector管理CBody,在update时进行一次判断碰撞并调用OnContact方法。

  4、为了方便显示上图的灰色矩形框需要用以下的类进行显示图形

  1. /*
  2. * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
  3. *
  4. * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com
  5. *
  6. * This software is provided 'as-is', without any express or implied
  7. * warranty. In no event will the authors be held liable for any damages
  8. * arising from the use of this software.
  9. * Permission is granted to anyone to use this software for any purpose,
  10. * including commercial applications, and to alter it and redistribute it
  11. * freely, subject to the following restrictions:
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. */
  20.  
  21. #ifndef RENDER_H
  22. #define RENDER_H
  23.  
  24. #include "Box2D/Box2D.h"
  25. #include "cocos2d.h"
  26.  
  27. struct b2AABB;
  28.  
  29. // This class implements debug drawing callbacks that are invoked
  30. // inside b2World::Step.
  31. class GLESDebugDraw : public b2Draw
  32. {
  33. float32 mRatio;
  34. cocos2d::GLProgram* mShaderProgram;
  35. GLint mColorLocation;
  36.  
  37. void initShader( void );
  38. public:
  39. GLESDebugDraw();
  40.  
  41. GLESDebugDraw( float32 ratio );
  42.  
  43. virtual void DrawPolygon(const b2Vec2* vertices, int vertexCount, const b2Color& color);
  44.  
  45. virtual void DrawSolidPolygon(const b2Vec2* vertices, int vertexCount, const b2Color& color);
  46.  
  47. virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color);
  48.  
  49. virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
  50.  
  51. virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
  52.  
  53. virtual void DrawTransform(const b2Transform& xf);
  54.  
  55. virtual void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color);
  56.  
  57. virtual void DrawString(int x, int y, const char* string, ...);
  58.  
  59. virtual void DrawAABB(b2AABB* aabb, const b2Color& color);
  60. };
  61.  
  62. #endif
  63. /*
  64. * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
  65. *
  66. * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com
  67. *
  68. * This software is provided 'as-is', without any express or implied
  69. * warranty. In no event will the authors be held liable for any damages
  70. * arising from the use of this software.
  71. * Permission is granted to anyone to use this software for any purpose,
  72. * including commercial applications, and to alter it and redistribute it
  73. * freely, subject to the following restrictions:
  74. * 1. The origin of this software must not be misrepresented; you must not
  75. * claim that you wrote the original software. If you use this software
  76. * in a product, an acknowledgment in the product documentation would be
  77. * appreciated but is not required.
  78. * 2. Altered source versions must be plainly marked as such, and must not be
  79. * misrepresented as being the original software.
  80. * 3. This notice may not be removed or altered from any source distribution.
  81. */
  82.  
  83. #include "GLES-Render.h"
  84. #include "cocos2d.h"
  85. #include <stdio.h>
  86. #include <stdarg.h>
  87. #include <string.h>
  88.  
  89. USING_NS_CC;
  90.  
  91. GLESDebugDraw::GLESDebugDraw()
  92. : mRatio( 1.0f )
  93. {
  94. this->initShader();
  95. }
  96.  
  97. GLESDebugDraw::GLESDebugDraw( float32 ratio )
  98. : mRatio( ratio )
  99. {
  100. this->initShader();
  101. }
  102.  
  103. void GLESDebugDraw::initShader( void )
  104. {
  105. mShaderProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
  106.  
  107. mColorLocation = glGetUniformLocation( mShaderProgram->getProgram(), "u_color");
  108. }
  109.  
  110. void GLESDebugDraw::DrawPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color)
  111. {
  112. mShaderProgram->use();
  113. mShaderProgram->setUniformsForBuiltins();
  114.  
  115. b2Vec2* vertices = new b2Vec2[vertexCount];
  116. for( int i=;i<vertexCount;i++)
  117. {
  118. vertices[i] = old_vertices[i];
  119. vertices[i] *= mRatio;
  120. }
  121.  
  122. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  123.  
  124. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , vertices);
  125. glDrawArrays(GL_LINE_LOOP, , vertexCount);
  126.  
  127. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,vertexCount);
  128.  
  129. CHECK_GL_ERROR_DEBUG();
  130.  
  131. delete[] vertices;
  132. }
  133.  
  134. void GLESDebugDraw::DrawSolidPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color)
  135. {
  136. mShaderProgram->use();
  137. mShaderProgram->setUniformsForBuiltins();
  138.  
  139. b2Vec2* vertices = new b2Vec2[vertexCount];
  140. for( int i=;i<vertexCount;i++) {
  141. vertices[i] = old_vertices[i];
  142. vertices[i] *= mRatio;
  143. }
  144.  
  145. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r*0.5f, color.g*0.5f, color.b*0.5f, 0.5f);
  146.  
  147. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , vertices);
  148.  
  149. glDrawArrays(GL_TRIANGLE_FAN, , vertexCount);
  150.  
  151. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  152. glDrawArrays(GL_LINE_LOOP, , vertexCount);
  153.  
  154. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,vertexCount*);
  155.  
  156. CHECK_GL_ERROR_DEBUG();
  157.  
  158. delete[] vertices;
  159. }
  160.  
  161. void GLESDebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
  162. {
  163. mShaderProgram->use();
  164. mShaderProgram->setUniformsForBuiltins();
  165.  
  166. const float32 k_segments = 16.0f;
  167. int vertexCount=;
  168. const float32 k_increment = 2.0f * b2_pi / k_segments;
  169. float32 theta = 0.0f;
  170.  
  171. GLfloat* glVertices = new GLfloat[vertexCount*];
  172. for (int i = ; i < k_segments; ++i)
  173. {
  174. b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
  175. glVertices[i*]=v.x * mRatio;
  176. glVertices[i*+]=v.y * mRatio;
  177. theta += k_increment;
  178. }
  179.  
  180. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  181. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , glVertices);
  182.  
  183. glDrawArrays(GL_LINE_LOOP, , vertexCount);
  184.  
  185. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,vertexCount);
  186.  
  187. CHECK_GL_ERROR_DEBUG();
  188.  
  189. delete[] glVertices;
  190. }
  191.  
  192. void GLESDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
  193. {
  194. mShaderProgram->use();
  195. mShaderProgram->setUniformsForBuiltins();
  196.  
  197. const float32 k_segments = 16.0f;
  198. int vertexCount=;
  199. const float32 k_increment = 2.0f * b2_pi / k_segments;
  200. float32 theta = 0.0f;
  201.  
  202. GLfloat* glVertices = new GLfloat[vertexCount*];
  203. for (int i = ; i < k_segments; ++i)
  204. {
  205. b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
  206. glVertices[i*]=v.x * mRatio;
  207. glVertices[i*+]=v.y * mRatio;
  208. theta += k_increment;
  209. }
  210.  
  211. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r*0.5f, color.g*0.5f, color.b*0.5f, 0.5f);
  212. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , glVertices);
  213. glDrawArrays(GL_TRIANGLE_FAN, , vertexCount);
  214.  
  215. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  216. glDrawArrays(GL_LINE_LOOP, , vertexCount);
  217.  
  218. // Draw the axis line
  219. DrawSegment(center,center+radius*axis,color);
  220.  
  221. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,vertexCount*);
  222.  
  223. CHECK_GL_ERROR_DEBUG();
  224.  
  225. delete[] glVertices;
  226. }
  227.  
  228. void GLESDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
  229. {
  230. mShaderProgram->use();
  231. mShaderProgram->setUniformsForBuiltins();
  232.  
  233. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  234.  
  235. GLfloat glVertices[] =
  236. {
  237. p1.x * mRatio, p1.y * mRatio,
  238. p2.x * mRatio, p2.y * mRatio
  239. };
  240. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , glVertices);
  241.  
  242. glDrawArrays(GL_LINES, , );
  243.  
  244. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,);
  245.  
  246. CHECK_GL_ERROR_DEBUG();
  247. }
  248.  
  249. void GLESDebugDraw::DrawTransform(const b2Transform& xf)
  250. {
  251. b2Vec2 p1 = xf.p, p2;
  252. const float32 k_axisScale = 0.4f;
  253. p2 = p1 + k_axisScale * xf.q.GetXAxis();
  254. DrawSegment(p1, p2, b2Color(,,));
  255.  
  256. p2 = p1 + k_axisScale * xf.q.GetYAxis();
  257. DrawSegment(p1,p2,b2Color(,,));
  258. }
  259.  
  260. void GLESDebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
  261. {
  262. mShaderProgram->use();
  263. mShaderProgram->setUniformsForBuiltins();
  264.  
  265. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  266.  
  267. // glPointSize(size);
  268.  
  269. GLfloat glVertices[] = {
  270. p.x * mRatio, p.y * mRatio
  271. };
  272.  
  273. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , glVertices);
  274.  
  275. glDrawArrays(GL_POINTS, , );
  276. // glPointSize(1.0f);
  277.  
  278. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,);
  279.  
  280. CHECK_GL_ERROR_DEBUG();
  281. }
  282.  
  283. void GLESDebugDraw::DrawString(int x, int y, const char *string, ...)
  284. {
  285. // NSLog(@"DrawString: unsupported: %s", string);
  286. //printf(string);
  287. /* Unsupported as yet. Could replace with bitmap font renderer at a later date */
  288. }
  289.  
  290. void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color)
  291. {
  292. mShaderProgram->use();
  293. mShaderProgram->setUniformsForBuiltins();
  294.  
  295. mShaderProgram->setUniformLocationWith4f(mColorLocation, color.r, color.g, color.b, );
  296.  
  297. GLfloat glVertices[] = {
  298. aabb->lowerBound.x * mRatio, aabb->lowerBound.y * mRatio,
  299. aabb->upperBound.x * mRatio, aabb->lowerBound.y * mRatio,
  300. aabb->upperBound.x * mRatio, aabb->upperBound.y * mRatio,
  301. aabb->lowerBound.x * mRatio, aabb->upperBound.y * mRatio
  302. };
  303.  
  304. glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, , GL_FLOAT, GL_FALSE, , glVertices);
  305. glDrawArrays(GL_LINE_LOOP, , );
  306.  
  307. CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(,);
  308.  
  309. CHECK_GL_ERROR_DEBUG();
  310. }

  然后在CBody的draw中做如下处理进行绘制

  1. #ifdef DRAW_BODY
  2. void CBody::onDraw(const Mat4 &transform, uint32_t flags)
  3. {
  4.  
  5. if (m_debugDraw)
  6. {
  7. b2Vec2 vs[];
  8. const Rect rect = GetRect();
  9. vs[].Set(rect.origin.x, rect.origin.y);
  10. vs[].Set(rect.origin.x + rect.size.width, rect.origin.y);
  11. vs[].Set(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height);
  12. vs[].Set(rect.origin.x, rect.origin.y + rect.size.height);
  13. m_debugDraw->DrawSolidPolygon(vs, , b2Color(0.6f, 0.6f, 0.6f));
  14. }
  15. }
  16. void CBody::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
  17. {
  18. //_globalZOrder
  19. m_pCustomCommand.init();
  20. m_pCustomCommand.func = CC_CALLBACK_0(CBody::onDraw, this, transform, flags);
  21. renderer->addCommand(&m_pCustomCommand);
  22. }
  23. #endif

  5、最后在Monster等实体类init中添加该CBody的实例,即可为其添加碰撞形状。

如下:

  1. m_pBody = CBody::create();
  2. m_pBody->SetGroupMask(enGroupMask::GROUP_MONSTER);
  3. m_pBody->SetRect(-, -, , );
  4. this->addChild(m_pBody);

三、定义CDamage用于创建伤害

主要实现以下方法:

  1. #ifndef __CDamage_H__
  2. #define __CDamage_H__
  3. #include "IGameDef.h"
  4. #include "Body.h"
  5. #include <set>
  6. USING_NS_CC;
  7. class CDamage : public Node
  8. {
  9. public:
  10. // implement the "static create()" method manually
  11. CREATE_FUNC(CDamage);
  12.  
  13. virtual bool init();
  14.  
  15. void update(float dt);
  16.  
  17. void SetRect(float x, float y, float w, float h);
  18.  
  19. void SetGroupMask(enGroupMask nGroupMask);
  20.  
  21. void OnContact(CBody* pBody);
  22. private:
  23.  
  24. CDamage();
  25. ~CDamage();
  26.  
  27. int m_nDieTime; // 伤害区域消失时间
  28.  
  29. CBody *m_pBody;
  30.  
  31. std::set<CBody*> m_sContact;
  32. };
  33. #endif __CDamage_H__

关键点:
  1、m_nDieTime在update中实现控制伤害区域存在时间

  2、m_sContact控制一个CDamage实例对每个实体仅造成一次伤害。

在怪物等攻击动作中添加事件并在事件回调中添加如下代码创建伤害

  1. void CEntity::ActionEvent(Frame *frame)
  2. {
  3. cocostudio::timeline::EventFrame* evnt = dynamic_cast<cocostudio::timeline::EventFrame*>(frame);
  4. if (!evnt)
  5. return;
  6. std::string str = evnt->getEvent();
  7. if (str == "attack")
  8. {
  9. auto damage = CDamage::create();
  10. damage->SetRect(-, -, , );
  11. damage->SetGroupMask(m_nGroupMask);
  12. if (this->getScaleX()<)
  13. {
  14. damage->setPositionX(-);
  15. }
  16. this->addChild(damage);
  17. }
  18. }

添加事件方法,即在特定帧添加以下的帧事件
     

至此,游戏的基本元素已经都有了。

剩下的自己可以进行扩展了,如:血量为0时,播放死亡动画,并显示失败等。

  

在怪物死亡创建一个新的怪物:

  

  

cocos2dx - 伤害实现的更多相关文章

  1. cocos2dx - android环境配置及编译

    接上一节内容:cocos2dx - 伤害实现 本节主要讲Android环境配置及编译 在第一节中setup.py的配置里,我们没有配置对应的ndk,sdk,ant的路径,在这里需要先配置好环境变量. ...

  2. 【cocos2d-x 手游研发小技巧(1)自定义制作怪物伤害数值】

    直插主题了,今天写了一下午,早就想要写这类似东西的,首先我不会选用CCLabelAtlas了,我直接用帧图片做. 首先我们要准备素材,我先把素材帖出来给大家: 这个是一张比较全的素材图,它包含了扣血的 ...

  3. 【cocos2d-x 手游研发----目录】

    感谢大家一直支持我写这样一系列的博客,从中我自己也获益良多,cocos2d-x这样一款非常棒的引擎,是值得我们去学习和分享的,谈到分享,那我就把这套写了差不多一两个月的框架给大家开源下载,写的很一般, ...

  4. Cocos2d-x 3.0 事件系统【转】

    事件系统,是一个软件的核心组成部分.从小处讲它是应用程序内部各模块交互的设计模式,从大处讲,它是软件架构的组成模块.在现代软件开发中,操作系统通常通过一些预定义的事件,告知应用程序发生的一些事情如用户 ...

  5. Cocos2dx 小技巧(十一) 小人虽短,但能够旋转

    转眼五一就到了,放假三天应该做些什么呢?窝在家里钻研技术?写博客?no no no no,这样的"伤害"自己的方式实在让我无法忍受.本来和大学那伙人越好了一起去哪里玩玩,喝酒聊天啥 ...

  6. Cocos2d-x 使用物理引擎进行碰撞检测

    [转自]: http://blog.csdn.net/cbbbc/article/details/38541099 通常在游戏简单逻辑判断和模拟真实的物理世界时,我们只需要在定时器中判断游戏中各个精灵 ...

  7. cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap

    背景 在上一篇博客中,我们提到CMGameScene,但是CMGameScene只是个框架,实际担任游戏逻辑的是CMGameMap类,这个博文就来了解下CMGameMap 头文件 class CMGa ...

  8. cocos2dx调用浏览器打开网址

    安卓端cocos2dx/platform/android路径下CCApplication.h: virtual void openURL(const char* pszUrl); CCApplicat ...

  9. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

随机推荐

  1. 【Beta】 第五次Daily Scrum Meeting

    一.本次会议为第五次meeting会议 二.时间:10:00AM-10:20AM 地点:陆大楼 三.会议站立式照片 四.今日任务安排 成员 昨日任务 今日任务 林晓芳 帮助完善登录界面 对目前完成的模 ...

  2. 201521123042《Java程序设计》 第7周学习总结

    1. 本周学习总结 网上看了很多资料,发现这一张图总结的还不错就引用过来了.但是最上面的Map和Collection之间的关系应该是依赖,不是Produces. ①概述:Java集合框架主要包括两种类 ...

  3. 静态include与动态include的区别

    jsp中的include有两种形式,分别是:<%@ include file=""%><jsp:include page="" flush=& ...

  4. 201521123093 java 第十四周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. MySQL中的库操作和表操作 库操作: 显示所有数据库: show databases; 创建数据库: crea ...

  5. 201521123078 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 1.题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常. ...

  6. 201521123068 《java程序设计》 第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 多线程的冲突:同时运行的线程需要访问共享数据(临界资源) 多线程的互斥访问:两个或两个以上的线程需要同时对同一数据 ...

  7. Java: private、protected、public和default的区别

    public: 具有最大的访问权限,可以访问任何一个在classpath下的类.接口.异常等.它往往用于对外的情况,也就是对象或类对外的一种接口的形式. protected: 主要的作用就是用来保护子 ...

  8. 练习使用markdown

    我的随笔 写随笔的原因 1 完全是为了练习使用markdown编辑器 2 我是个爱学习的宝宝 3 学习能力问题? 随笔内容 弄懂markdown语法 随便谢谢心情 个人心情 冷漠 不想说话 神经 个人 ...

  9. Python数据类型方法精心整理,不必死记硬背,看看源码一切都有了

    Python认为一切皆为对象:比如我们初始化一个list时: li = list('abc') 实际上是实例化了内置模块builtins(python2中为__builtin__模块)中的list类: ...

  10. Vue-cli创建项目从单页面到多页面

    vue-cli创建项目从单页面到多页面 对于某些项目来说,单页面不能很好的满足需求,所以需要将vue-cli创建的单页面项目改为多页面项目. 需要修改以下几个文件: 1.下载依赖glob $npm i ...