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而来的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值