通过前边三节课程,我们的游戏有了地图和主角,而且主角不再会跑出地图,但仅仅这样还不够,还要让游戏主角有更大的移动范围。
创建一个“三方控制器”用来取代之前的SimpleMoveController.
ThreeDirectionController.h:

基本上和SimpleMoveController类差不多,区分了X和Y方向上的速度,以及加入了触屏事件(继承自CCLayer),所以,Controller.h中要把继承类CCNode改为CCLayer!
ThreeDirectionController.cpp:



最后,打开TollgateScene.cpp的addPlayer函数,将SimpleMoveController替换为ThreeDirectionController,如下:

运行项目,单击屏幕,就可以看到主角上下移动了。