cocos2dx3.3开发FlappyBird总结十五:记录玩家得分

在游戏结束时,需要更新和获取最新得分。

设计一个工具类,只有类方法,这样外部就能很方便地获取和更新值。

/** * This is a help class,using to operate the user information conveniencely */
class RecordTool {
public:
  /** * Get the best score with a key,store in the UserDefault */
  static int getBestscore();

  /** * Update a new score in the local UserDefault * * @param bestscore The new value of score */
  static void setBestscore(int bestscore);
};

#endif /* defined(__EngryBird__RecordTool__) */

这种写法有很多好处,比如外部不需要传key,由内部控制,这样就不会全工程散落了,维护起来就简单多了。

实现是很简单的,是使用UserDefault来管理的,这个类是引擎提供的,跟IOS的NSUserDefault的使用是很像的,毕竟引擎是由2d而来的。

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...