Why do sprites with the same setPosition point appear so far apart?

Given the following code, why are the Circle and Rectangle images displaying so far apart?

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

Here is the code used to create the Rectangle:

glColor4ub(255, 255, 255, 255);
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;



You set position for your rectangle to the center of the screen. Then you draw first vertice with coordinates (79.f, 299.f). So it draws in the right-top corner. Because it draws relative to the Rectangle's instance position.

Need Your Help

Big-O analysis for a loop

algorithm loops for-loop big-o

I've got to analyze this loop, among others, and determine its running time using Big-O notation.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.