鉴于以下代码,为什么圆形和矩形图像显示相距甚远?
CGPoint center = ccp(winSize.width/2, winSize.height/2);
[rectangle setPosition:center];
[circle setPosition:ccp(winSize.width/2, winSize.height/2)];
以下是用于创建Rectangle的代码:
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;
}
答案 0 :(得分:0)
您可以将矩形的位置设置为屏幕中心。然后用坐标(79.f,299.f)绘制第一个顶点。所以它吸引了右上角。因为它相对于Rectangle的实例位置绘制。