mintuz
mintuz

Reputation: 721

cocos2d coordinates system

        CCLabelTTF *label = [CCLabelTTF labelWithString:@"Score : #" fontName:@"Arial" fontSize:14];

        // ask director the the window size
        CGSize size = [[CCDirector sharedDirector] winSize];

        // position the label on the center of the screen
        label.position =  ccp( size.width + 0, size.height + 0 );

        // add the label as a child to this Layer
        [self addChild: label];

        label.position =  ccp( size.width + 0, size.height + 0 );

how would i get that label in the bottom left corner. I do not understand the coordinates system very well. From what I understand Y is bottom. X is far left. so how come when I use that code, the position of the label is top right. My application is portrait.

Also would it better to have the label as a sprite, or just keep it like that. ( its to hold a score )

Upvotes: 1

Views: 2254

Answers (3)

Steve
Steve

Reputation: 6362

CCLabelTTF is expensive if updated rapidly (many times per second), but is fine if you're not updating it. One preferred way is to use CCLabelBMFont (I think that's the class...). You'll need the .fnt file and .png to go with it, but you can make those with a tool like Glyph Designer from 71squared.

Upvotes: 0

rptwsthi
rptwsthi

Reputation: 10182

consider first answer for your first question, and for second question answer is, if label is for score, then it's better you use label, rather than sprites(because you'll need 1000s of them and it'll be heavy as well as complicated)

Upvotes: 0

bensnider
bensnider

Reputation: 3772

In codos2d, the point (0,0) is the bottom left corner of the screen. Think of it as quadrant 1 on a x,y plane where x increases as you go right, and y increases as you go up.

So to get the label in the bottom left just do label.position = ccp(0, 0); but this might be the default so you might not have to do anything.

Upvotes: 3

Related Questions