视网膜显示坐标错误
我尝试在 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上却显示正确。 怎么了? 这个坐标转换有什么问题吗?
屏幕截图
I try to display image to the Screen at Retina iPhone.
So I used this code.
#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];
}
Unfortunately, the image doesn't display correctly.
The image's position is wrong.
But in other iphone, it display correct.
What's the matter?
What's the problem in this coordinate convert?
Screenshots
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是完全错误的:
这些宏的正确值:
这是因为您没有处理像素。您正在使用点,系统将为您计算像素。这意味着 iPhone 屏幕始终为 480x320 点。您也可以使用像素,但是您必须检查文档。
很快我将在此处添加文档中描述此问题的链接。
编辑添加的文档链接:点与像素
This is completely wrong:
The correct values of these macros:
This is because you are not working with pixels. You are working with points and the system will calculate the pixels for you. This means the iPhone screen is always 480x320
points
. You can also use pixels, but then you have to check the documentation.Soon I will add here a link to the description of this problem in the documentation.
Edit added documentation link: Points Versus Pixels