视网膜显示坐标错误

发布于 2024-12-05 06:12:49 字数 1273 浏览 1 评论 0原文

我尝试在 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

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心荒芜 2024-12-12 06:12:49

这是完全错误的:

#define ScreenWidth 960
#define ScreenHeight 640

这些宏的正确值:

#define ScreenWidth 480
#define ScreenHeight 320

这是因为您没有处理像素。您正在使用点,系统将为您计算像素。这意味着 iPhone 屏幕始终为 480x320 点。您也可以使用像素,但是您必须检查文档。
很快我将在此处添加文档中描述此问题的链接。


编辑添加的文档链接:点与像素

This is completely wrong:

#define ScreenWidth 960
#define ScreenHeight 640

The correct values of these macros:

#define ScreenWidth 480
#define ScreenHeight 320

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文