最近写lua写得没有力气了,所以想让脑袋放松一下,刚好看到有人在用swift做游戏:

Swift游戏实战-跑酷熊猫 

于是脑子一短路,就想到了利用这些素材来做一个游戏。

本来不想记笔记的,但是由于选择物理引擎的时候遇到诸多问题,所以选择记录下来,目前只做了个雏形,需要再完善一点。

 

需要知识:

1 cocos2dx-3.2 基本知识

2 box2d有一定的了解。

 

由于比较简单,所以把所有代码给上了先,然后再简单介绍下遇到的问题之类的东西。

首先是主角,熊猫类:

 1 #ifndef __PANDA_H__
 2 #define __PANDA_H__
 3 
 4 #include "cocos2d.h"
 5 USING_NS_CC;
 6 
 7 class Panda : public cocos2d::Node
 8 {
 9 public:
10     Vector<SpriteFrame*> run_frames;
11     Vector<SpriteFrame*> jump_effect_frames;
12     Vector<SpriteFrame*> roll_frames;
13     Vector<SpriteFrame*> jump_frames;
14     Animation * run_anim;
15     Animation * jump_anim;
16     Animation * jump_effect_anim;
17     Animation * roll_anim;
18     Sprite * shape;
19     Animation * anim;
20     int cur_state;//current state
21     // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
22     virtual bool init();  
23     //play status RUM||ROLL||JUMP etc
24     void play(unsigned int state);
25 
26     void updateState();
27     // implement the "static create()" method manually
28     CREATE_FUNC(Panda);
29 
30     int getCurrentState();
31     //panda 4 states
32     enum {
33         RUN = 1,
34         JUMP = 2,
35         JUMP2 = 3
36     };
37 };
38 
39 #endif // __PANDA_H__

相关文章:

  • 2021-07-02
  • 2021-08-20
  • 2021-10-20
  • 2021-09-06
  • 2021-04-26
  • 2021-10-05
  • 2021-10-19
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-05-24
  • 2021-07-28
  • 2022-12-23
相关资源
相似解决方案