Retina Display coordinate problem.
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?
|