Cocos2d iphone 要检索的宏[[CCDirector sharedDirector]winSize];

Cocos2d iphone 要检索的宏[[CCDirector sharedDirector]winSize];,cocos2d-iphone,Cocos2d Iphone,我发现自己经常调用[[CCDirector sharedDirector]winSize],我真的很想按照winSize()的思路制作一个宏。哪里可能是一个很好的地方把它塞进Cocos2D的库?起初我认为Support>CGPointExtension.h可能会起作用,但在那个位置没有定义ccdirector。有什么想法吗?我通常将这些定义放在每个项目的.m/.h中。例如,在.h extern float kScreenWidth; // design wid

我发现自己经常调用
[[CCDirector sharedDirector]winSize]
,我真的很想按照winSize()的思路制作一个宏。哪里可能是一个很好的地方把它塞进Cocos2D的库?起初我认为Support>CGPointExtension.h可能会起作用,但在那个位置没有定义ccdirector。有什么想法吗?

我通常将这些定义放在每个项目的.m/.h中。例如,在.h

extern float  kScreenWidth;                  // design width of the app (in points)
extern float  kScreenHeight;                 // design height of the app (in points)
extern CGSize kBattleMidPoint;
extern float  kLongTouch;
extern float  kTileWidth;
extern float  kTileHeight;
在下午

float  kScreenWidth  = 480.0;
float  kScreenHeight = 320.0;
CGSize kBattleMidPoint;
float  kLongTouch    = .65f;
float  kTileWidth    = 40.;
float  kTileHeight   = 40.;
以及.m setters中的某个地方,以覆盖上述默认值。在CCDirector初始化之后,我给他们打了一次电话

+ (void)setScreenWidth:(float)screenWidth {

    kScreenWidth = screenWidth;
    if (screenWidth >= 568.0) {
        kDeviceType = deviceTypeIpodTall;
    }
}

+ (void)setScreenHeight:(float)screenHeight {

    kScreenHeight = screenHeight;
}   

+ (void)setBattleMidPoint:(CGSize)midPoint {

    kBattleMidPoint = midPoint;
}

+ (void)setTileWidth:(float)tileWidth {

    kTileWidth = tileWidth;
}

+ (void)setTileHeight:(float)tileHeight {

    kTileHeight = tileHeight;
}

最后,我将.h包含在预编译头中。我倾向于避免(不惜一切代价)修改/扩展cocos2d代码库,保留以最小工作量进行更新的权利:)。

我通常将这些定义放在每个项目的.m/.h中。例如,在.h

extern float  kScreenWidth;                  // design width of the app (in points)
extern float  kScreenHeight;                 // design height of the app (in points)
extern CGSize kBattleMidPoint;
extern float  kLongTouch;
extern float  kTileWidth;
extern float  kTileHeight;
在下午

float  kScreenWidth  = 480.0;
float  kScreenHeight = 320.0;
CGSize kBattleMidPoint;
float  kLongTouch    = .65f;
float  kTileWidth    = 40.;
float  kTileHeight   = 40.;
以及.m setters中的某个地方,以覆盖上述默认值。在CCDirector初始化之后,我给他们打了一次电话

+ (void)setScreenWidth:(float)screenWidth {

    kScreenWidth = screenWidth;
    if (screenWidth >= 568.0) {
        kDeviceType = deviceTypeIpodTall;
    }
}

+ (void)setScreenHeight:(float)screenHeight {

    kScreenHeight = screenHeight;
}   

+ (void)setBattleMidPoint:(CGSize)midPoint {

    kBattleMidPoint = midPoint;
}

+ (void)setTileWidth:(float)tileWidth {

    kTileWidth = tileWidth;
}

+ (void)setTileHeight:(float)tileHeight {

    kTileHeight = tileHeight;
}
最后,我将.h包含在预编译头中。我倾向于避免(不惜一切代价)修改/扩展cocos2d代码库,保留以最小的工作量进行更新的权利:)。

这怎么样

#define WINSIZE [[CCDirector sharedDirector] winSize];
就我个人而言,我不会为此使用宏,更好的选择是向经常需要winSize的类中添加ivar或静态var。

这怎么样

#define WINSIZE [[CCDirector sharedDirector] winSize];

就个人而言,我不会为此使用宏,更好的选择是在经常需要winSize的类中添加ivar或静态变量。

这当然是一种方法。我希望能有一些不那么冗长的东西,更接近于普遍发展。尽管如此,这还是需要考虑的——谢谢。哈哈。。。嗯,我不从事构建和发布框架的业务。这对我们的团队很有效。但没有什么能打败精灵。位置=ccp(kScreenWidth/2,kScreenHeight/2);在代码库的任何地方,它都尽可能简洁。:)这当然是一种方法。我希望能有一些不那么冗长的东西,更接近于普遍发展。尽管如此,这还是需要考虑的——谢谢。哈哈。。。嗯,我不从事构建和发布框架的业务。这对我们的团队很有效。但没有什么能打败精灵。位置=ccp(kScreenWidth/2,kScreenHeight/2);在代码库的任何地方,它都尽可能简洁。:)