我尝试将图像显示在Retina iPhone的屏幕上。 所以我使用了这段代码。
#define ScreenWidth 960
#define ScreenHeight 640
void ConvertCoordf(float* x, float* y)
{
int height = ScreenHeight;
if ( height / 2 > *y )
*y += (height / 2 - *y) * 2;
else if ( height / 2 < *y )
*y -= (*y - height / 2) * 2;
}
void DISPLAY_UPDATE(char *name, int x , int y , int startx, int starty , int w , int h ,float rotation)
{
CCSprite *sprite = [[CCSprite spriteWithFile:[NSString stringWithUTF8String:name] rect:CGRectMake(startx, starty, w, h)] retain];
float drawX = x, drawY = y;
CGSize size = [sprite contentSize];
int nWidth = size.width;
int nHeight = size.height;
drawX = drawX + nWidth/2;
drawY = drawY - nHeight/2;
ConvertCoordf(&drawX, &drawY);
drawY -= nHeight;
[sprite setPosition:ccp(drawX, drawY)];
[sprite setAnchorPoint:CGPointMake(0.5, 0.5)];
[sprite setRotation:rotation];
[_mainLayer addChild:sprite];
[sprite release];
}
不幸的是,图像无法正确显示。 图像的位置是错误的。 但在其他iPhone,它显示正确。 怎么了? 这个坐标转换有什么问题?
答案 0 :(得分:2)
这是完全错误的:
#define ScreenWidth 960
#define ScreenHeight 640
这些宏的正确值:
#define ScreenWidth 480
#define ScreenHeight 320
这是因为您没有使用像素。您正在使用点,系统将为您计算像素。这意味着iPhone屏幕始终为480x320 points
。您也可以使用像素,但是您必须检查文档
很快我会在文档中添加指向此问题描述的链接。
修改添加的文档链接:Points Versus Pixels