Cocos2d-x Prefix.pch 文件的用法

原文地址:http://blog.csdn.net/kodeyang/article/details/10493973


Prefix.pch 中引入的头文件、定义的宏可以在整个工程的范围内被使用,

不过有一个弊端,只要你对 Prefix.pch 文件略作修改,就将导致重新编译所有源码文件。

下面是我所常用的一种 Prefix.pch 配置:

Prefix.pch

[cpp]  view plain copy
  1. #ifdef __OBJC__  
  2.     #import <Foundation/Foundation.h>  
  3.     #import <UIKit/UIKit.h>  
  4. #endif  
  5.   
  6. /** 
  7.  * 获取 Scene 对象的快捷方法 
  8.  */  
  9. #define SCENE_FUNC(__TYPE__) \  
  10. static CCScene* scene() { \  
  11.     CCScene* t_pScene = CCScene::create(); \  
  12.     __TYPE__* t_pLayer = __TYPE__::create(); \  
  13.     t_pScene->addChild(t_pLayer); \  
  14.     return t_pScene; \  
  15. }  
  16.   
  17. /** 
  18.  * 打印 CCDictionary~ 
  19.  */  
  20. #define CCDICT_ECHO(__DICT__) \  
  21. do { \  
  22.     CCDictElement* t_pDictElement = NULL; \  
  23.     CCDICT_FOREACH(__DICT__, t_pDictElement) { \  
  24.         const char* tmp_pArrCharKey = t_pDictElement->getStrKey(); \  
  25.         CCString* tmp_pCcStrVal = (CCString*)t_pDictElement->getObject(); \  
  26.         const char* tmp_pArrCharVal = tmp_pCcStrVal->getCString(); \  
  27.         printf("+++ [key = %s, value = %s] +++\n", tmp_pArrCharKey, tmp_pArrCharVal); \  
  28.     } \  
  29. while(0)  
  30.   
  31. /** 
  32.  * 单例~ 
  33.  */  
  34. #define sDirector       CCDirector::sharedDirector()  
  35. #define sUserDefault    CCUserDefault::sharedUserDefault()  
  36. #define sTexCache       CCTextureCache::sharedTextureCache()  
  37. #define sFrameCache     CCSpriteFrameCache::sharedSpriteFrameCache()  
  38.   
  39. /** 
  40.  * 命名空间~ 
  41.  */  
  42. #define USING_NS_STD    using namespace std  
  43.   
  44. /** 
  45.  * 从绝对路径获取文件名~ 
  46.  */  
  47. #define __FILE_NAME__ ((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)  
  48.   
  49. /** 
  50.  * 调试打印~ 
  51.  */  
  52. #ifdef DEBUG  
  53. #define KYLog(fmt, ...) \  
  54. printf(("【文件】%s\n【方法】%s\n【行号】%d\n" fmt "\n【结束】\n\n"), __FILE_NAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__);  
  55. #else  
  56. #define KYLog(...);  
  57. #endif  
  58.   
  59. /** 
  60.  * 带开关,带换行的 log 
  61.  */  
  62. #ifdef DEBUG  
  63. #define println(fmt, ...) printf((fmt "\n"), ##__VA_ARGS__);  
  64. #else  
  65. #define println(...);  
  66. #endif  

PS: 

【编程好习惯】精确包含头文件 http://blog.csdn.net/wk3368/article/details/39495481

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值