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 8048409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:25:36+00:00 2026-06-05T06:25:36+00:00

I have a CClayer class and when this class inits it creates a CCSprite

  • 0

I have a CClayer class and when this class inits it creates a CCSprite that should be centered, so later, when I rotate an object created with that CCLayer class, it rotates around its center. I mean, if the sprite on that class is an image 200 pixels wide and 300 pixels height, I want the CCLayer pivot to be at 100,150.

I have tried to set it at 0,0 and 0.5,0.5 without success.

As far as I understand, CCLayer has no bounding box, it is like a kind of node, right? so, I create the class like this:

-(id) initWithImage:(UIImage*)image Name:(NSString*)name
{

    if( (self=[super init])) {

        self.isTouchEnabled = YES;

        self.mySprite = 
            [CCSprite spriteWithCGImage:image.CGImage key:name];

        self.mySprite.position = CGPointZero;
        [self addChild:self.mySprite];

        self.mySprite.anchorPoint = ccp(0.0f, 0.0f);
        // have tried also 0.5f, 0.5f... no success        
    }

    return self;
}

How do I do that?

thanks

  • 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-06-05T06:25:37+00:00Added an answer on June 5, 2026 at 6:25 am

    Provide a method in your CCLayer subclass to rotate the sprite:

    -(void) rotateMySpriteToAngle:(float) angle
    {
        self.mySprite.rotation = angle;
    }
    

    The anchor point of the sprite should be (0.5, 0.5) to rotate it about its centre.

    I feel you are making your program too complex though? Could you just use a sprite instead of a layer with a sprite as a child? Then you could rotate it directly.

    It looks as though you want to make your sprite touchable. Consider using CCMenu and CCMenuItems if you are looking to implement buttons.


    Edit

    Try setting the anchor point of the layer to (0, 0) and the anchor point of the sprite to (0.5, 0.5), then set the position of the sprite to (0, 0)

    This means the centre of the sprite is at (0, 0) on the layer and you then rotate the layer around it’s origin.

                        Scene
    =============================================
    =                                           =
    =                                           =
    =                                           =
    =                                           =
    =       |                                   =
    =       | Layer (effective infinite size)   =
    =     __|__                                 =
    =    |  |  |                                =
    =    |  +--|--------------                  =
    =    |_____|                                =
    =     Sprite                                =
    =============================================
    The + is the origin of the layer and the center point of the sprite
    When you rotate the layer around it's origin, you are simultaneously rotating the sprite about it's centre.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CCLayer class where I create an animated sprite that is the
I have a UIView class that I am using to have a CALayer. This
I have a cclayer class with invisible button that is the size of the
I have a CCLayer class (yes, it has to be a CCLayer, not CCSprite)
I have a little app up that has both CCLayer view and UIView. That
I have a strange problem while working with CCSprite subclass Creature. Lets,my object is
I have a class that takes an NSString as a parameter, uses Core Text
class token { private: char m_chIcon; //actual ascii char that shows up for this
When run this code, it gives me a strange error. I have a class
I have written a custom class that depends significantly on touch dragging/positioning, outside of

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.