0

给定以下代码,为什么圆形和矩形图像显示的距离如此之远?

CGPoint center = ccp(winSize.width/2, winSize.height/2);
[rectangle setPosition:center];
[circle setPosition:ccp(winSize.width/2, winSize.height/2)];

这是用于创建矩形的代码:

glEnable(GL_LINE_SMOOTH);
glColor4ub(255, 255, 255, 255);
glLineWidth(2);
CGPoint vertices2[] = { ccp(79,299), ccp(134,299), ccp(134,229), ccp(79,229) };
ccDrawPoly(vertices2, 4, YES);

在此处输入图像描述

-(id) init {
if((self = [super init])) {
    CGSize winSize = [CCDirector sharedDirector].winSize;

    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGB565];
    background = [CCSprite spriteWithFile:@"blue-shooting-stars.png"];
    background.anchorPoint = ccp(0,0);
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_Default];
    Circle *circle = [[Circle alloc] init];
    [circle setPosition:ccp(winSize.width/2.0f, winSize.height/2.0f)];

    CGPoint center = ccp(winSize.width/2.0f, winSize.height/2.0f);

    Rectangle *rectangle = [[Rectangle alloc] init];
    [rectangle setPosition:center];

    [self addChild:circle];
    [self addChild:rectangle];
}
return self;

}

4

1 回答 1

0

您将矩形的位置设置为屏幕的中心。然后用坐标 (79.f, 299.f) 绘制第一个顶点。所以它在右上角绘制。因为它是相对于 Rectangle 的实例位置绘制的。

于 2013-04-15T12:21:48.957 回答