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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:24:16+00:00 2026-05-22T11:24:16+00:00

Okay, I am going to post some code so you can see what I

  • 0

Okay, I am going to post some code so you can see what I am doing and then at the end I will ask my question.

In my Weapon class to create and animate it:

-(id) initWithWeapon
{
    // Load the Texture Atlas sprite frames, this also loads the Texture with the same name.
    CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    [frameCache addSpriteFramesWithFile:@"weapon1.plist"];
    if ((self = [super initWithSpriteFrameName:@"Gun_image.png"])) {
        // create an animation object from all the sprite animation frames
        CCAnimation* anim = [CCAnimation animationWithFrame:@"Gun" frameCount:30 delay:0.08f];

        // run the animation by using the CCAnimate action
        CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
        CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];
        [self runAction:repeat];
    }
    self.scale = 0.35f;
    return self;
}

This is the the method called above that handles the animation:

// Creates an animation from sprite frames.
+(CCAnimation*) animationWithFrame:(NSString*)frame frameCount:(int)frameCount delay:(float)delay
{
    // load the weapon's animation frames as textures and create a sprite frame
    NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];
    for (int i = 0; i < frameCount; i++)
    {
        NSString* file = [NSString stringWithFormat:@"%@%i.png", frame, i];
        CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
        CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
        [frames addObject:frame];
    }

    // return an animation object from all the sprite animation frames
    return [CCAnimation animationWithFrames:frames delay:delay];
}

So my problem is that when I scale the instance of the Weapon class (like I show above – self.scale = 0.35f) it scales down to left bottom corner, almost like the anchor point is set to [0.0,0.0] instead of [0.5,0.5] and I want it to just scale from the center of the sprite. I have put in some NSLogs and it says the anchor point is at [0.5,0.5]. Can anyone help me figure this out?

  • 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-22T11:24:17+00:00Added an answer on May 22, 2026 at 11:24 am

    — Problem solved —

    I must say, I was a little frustrated with this so I left it alone for awhile thinking that maybe after some time had passed I could meander over to it again and perhaps find a solution…THE STRATEGY WORKED!

    Originally I tried scaling it in the Weapon class, like I show, and also in the gamelayer class where I make an instance of the Weapon class and in both cases the image was only scaling down to the bottom left corner—I also was making sure to set the anchor point to [0.5f,0.5f].

    So this time I tried setting the anchor point and scaling it after it was added to the screen and not before:

    Before –

    WeaponClass *theWeapon = [WeaponClass weapon];
    theWeapon.position = ccp(theScroll.viewSize.width * 0.5f,theScroll.viewSize.height * 0.5f);
    theWeapon.anchorPoint = ccp(0.5f,0.5f);
    theWeapon.scale = 0.5f;;
    [theScroll addChild:theWeapon];
    

    After –

    WeaponClass *theWeapon = [WeaponClass weapon];
    theWeapon.position = ccp(theScroll.viewSize.width * 0.5f,theScroll.viewSize.height * 0.5f);
    [theScroll addChild:theWeapon];
    theWeapon.anchorPoint = ccp(0.5f,0.5f);
    theWeapon.scale = 0.5f;;
    

    I feel like kicking myself for not thinking to try such a simple thing as this, but anyway it is working as I need it to now.

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

Sidebar

Related Questions

Okay, I will just leave my code here . As you can see from
I have this code, and for some reason my $.post function fires twice in
Okay, this question is just getting more and more complex, so I'm going to
Okay, so I'm going to take the off chance that someone here has used
Is it okay to get a read-only collection from an aggregate without going through
I'm not sure what's going on, but on my own laptop, everything works okay.
Okay so im working on this php image upload system but for some reason
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
I'm doing some simple client side validation with jQuery. var passedValidation = new Boolean(true);
Okay this one may be a bit out from left field, but I'm going

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.