Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:15:20+00:00 2026-05-26T15:15:20+00:00

This is my first game in Cocos2D. I am using Cocos2D 1.0.1. I want

  • 0

This is my first game in Cocos2D. I am using Cocos2D 1.0.1. I want to add text on moving sprites which should be center aligned. I’ve taken a CCLabelTTF with a text on it but I cannot make it center aligned. This is what I’ve done so far:-

-(void)addTarget {

int enType= arc4random() % 11;

CCSprite *target=[CCSprite spriteWithFile:[NSString stringWithFormat:@"balloon%d.png",enType] rect:CGRectMake(0, 0, 100, 119)];

label = [[CCLabelTTF alloc] initWithString:@"H!" dimensions:CGSizeMake([target contentSize].width, [target contentSize].height)  
                                 alignment:UITextAlignmentCenter fontName:@"verdana" fontSize:20.0f];

 label.color = ccc3(60,60,60);

[target addChild:label z: 10];

// Create the actions

id actionMove = [CCMoveTo actionWithDuration:rangeDuration position:ccp(actualX,winSize.height+target.contentSize.height)];

[target runAction:[CCSequence actions:actionMove, nil]];

//[label setPosition:target.position];


// Add to targets array 

[targets addObject:target];

}

Somewhere I’ve read that adding “[label setPosition:target.position];” in action of sprite will make it center aligned but in vain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:15:21+00:00Added an answer on May 26, 2026 at 3:15 pm

    Try setting your label position here instead:

    label = [[CCLabelTTF alloc] initWithString:@"H!" dimensions:CGSizeMake([target contentSize].width, [target contentSize].height)  
                                     alignment:UITextAlignmentCenter fontName:@"verdana" fontSize:20.0f];
    //LABEL POSITION HERE
    label.position = ccp(0, 40);
     label.color = ccc3(60,60,60);
    

    You may have to play with the position values until you get it where you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first game I'm working on in C++ using OpenGL for graphics
I am coding my first iPhone game with cocos2D. And I want to save
I just started a game using cocos2d-iphone and I am trying to add a
i want to authenticate users using firstname and lastname This is the code i
I'm making a game on iPhone using cocos2d, and I have a question. In
Experimenting with Cocos2D collection detection and have some questions. First, some background: This is
I'm currently working on a new game for iOS using Cocos2D. The game needs
In my cocos2d game i have a some balls which must be destroyed, and
I am currently making a game for the iphone using cocos2d. The game runs
I am creating my first game ever using pygame and I've found that in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.