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

  • Home
  • SEARCH
  • 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 8502621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:32:12+00:00 2026-06-11T01:32:12+00:00

There is a class associated with the program Physics Editor called GB2ShapeCache that loads

  • 0

There is a class associated with the program Physics Editor called GB2ShapeCache that loads shapes that I make in the program. I noticed that it is not currently possible to change the scale of the shapes on the fly so I would like to be able to scale the fixtures for the shapes that I made in Physics Editor. Now the scale of my CCSprite in my app can be random so currently in the addShapesWithFile method, I do this for polygons:

vertices[vindex].x = (offset.x * sprite.scaleX) / ptmRatio_;
vertices[vindex].y = (offset.y * sprite.scaleY) / ptmRatio_;

and this for circles:

circleShape->m_radius = ([[circleData objectForKey:@"radius"] floatValue] / ptmRatio_) *sprite.scale;

I also changed the method so that I can pass in my sprite so I can get the scale to:

-(void) addShapesWithFile:(NSString*)plist forSprite:(CCSprite*)sprite

so that I can pass in my sprite so I can get the scale.

HOWEVER, I find this to be inefficient because I should not have to reload ALL my shapes in my plist since they are already added.

So is there any way to do what I am doing now but in the addFixturesToBody method? This way I do not re-create the already added plist shapes and I only scale the fixtures when it is ready to be added to my body.

If anyone needs to see more code or needs more info, feel free to ask. I know this issue must be simple!!!

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-11T01:32:13+00:00Added an answer on June 11, 2026 at 1:32 am

    I would recommend implementing it in the addFixturesToBody method.
    (see https://github.com/AndreasLoew/GBox2D/blob/master/GBox2D/GB2ShapeCache.mm)

    Try this method below, this should scale the shapes accordingly to the sprite’s they are for. Just pass in your CCSprite and this method will handle the rest.

    - (void)addFixturesToBody:(b2Body*)body forShapeName:(NSString*)shape forSprite:(CCSprite*)sprite {
        BodyDef *so = [shapeObjects_ objectForKey:shape];
        assert(so);
    
        FixtureDef *fix = so->fixtures;
    
        if ((sprite.scaleX == 1.0f) && (sprite.scaleY == 1.0f)) {
            // simple case - so do not waste any energy on this
            while(fix) {
                body->CreateFixture(&fix->fixture);
                fix = fix->next;
            }
        } else {
            b2Vec2 vertices[b2_maxPolygonVertices];
            while(fix) {
                // make local copy of the fixture def
                b2FixtureDef fix2 = fix->fixture;
    
                // get the shape
                const b2Shape *s = fix2.shape;
    
                // clone & scale polygon
                const b2PolygonShape *p = dynamic_cast<const b2PolygonShape*>(s);
                if(p)
                {
                    b2PolygonShape p2;
                    for(int i=0; i<p->m_vertexCount; i++)
                    {
                        vertices[i].x = p->m_vertices[i].x * sprite.scaleX;
                        vertices[i].y = p->m_vertices[i].y * sprite.scaleY;
                    }
                    p2.Set(vertices, p->m_vertexCount);
                    fix2.shape = &p2;
                }
    
                // clone & scale circle
                const b2CircleShape *c = dynamic_cast<const b2CircleShape *>(s);
                if(c) {
                    b2CircleShape c2;
                    c2.m_radius = c->m_radius * sprite.scale;
                    c2.m_p.x = c->m_p.x * sprite.scaleX;
                    c2.m_p.y = c->m_p.y * sprite.scaleY;
                    fix2.shape = &c2;
                }
    
                // add to body
                body->CreateFixture(&fix2);
                fix = fix->next;
            }    
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working in a class library and there are other source projects associated with
Is there a class that overwrites the .MainMenu_MenuItem class for the Main Menu? I
Is there a class in the ASP.NET MVC framework that represents a controller name
Is there a class in the .NET BCL that can store a block of
Simple question: Is there a class or interface that encapulates the getting of a
I want to make a program that pulls objects from a sql database and
I have a QT class instance, called C, (C inherits QOBJECT) that sends a
So, I'm writing a program for Android. Right now, I'm in a class called
There is class Road with its Road.h and Road.cpp which contains implementation of method
Say there is: class A(B): ... where B could be object and ... is

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.