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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:28:55+00:00 2026-05-28T23:28:55+00:00

I am new to cocos2d and first I learned how to make a circle

  • 0

I am new to cocos2d and first I learned how to make a circle then a square and now I learned how to create a polygon with an amount of vertices that I pick with a “b2polygonshape polygon” and here is my code for that

-(void) createDynamicPoly:(CGPoint)p;
{

b2BodyDef bodyDefPoly;
bodyDefPoly.type = b2_dynamicBody; 
bodyDefPoly.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
b2Body *polyBody = world->CreateBody(&bodyDefPoly);

int count = 8;
b2Vec2 vertices[8];

vertices[0].Set(10.0f/PTM_RATIO,0.0/PTM_RATIO);
vertices[1].Set(20.0f/PTM_RATIO,0.0f/PTM_RATIO);
vertices[2].Set(30.0f/PTM_RATIO,10.0f/PTM_RATIO);
vertices[3].Set(30.0f/PTM_RATIO,20.0f/PTM_RATIO); 
vertices[4].Set(20.0f/PTM_RATIO,30.0f/PTM_RATIO);
vertices[5].Set(10.0f/PTM_RATIO,30.0f/PTM_RATIO); 
vertices[6].Set(00.0f/PTM_RATIO,20.0f/PTM_RATIO);
vertices[7].Set(0.0f/PTM_RATIO,10.0f/PTM_RATIO);

b2PolygonShape polygon; 
polygon.Set(vertices, count);

b2FixtureDef fixtureDefPoly;
fixtureDefPoly.shape = &polygon;
fixtureDefPoly.density = 1.0f;
fixtureDefPoly.friction = 0.3f;
polyBody->CreateFixture(&fixtureDefPoly);


}

My question is how can I actively change the vertices of this polygon and it change the shape on my screen, without drawing a new shape. My over all goal is to create a free flowing blob.

Thankyou

  • 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-28T23:28:55+00:00Added an answer on May 28, 2026 at 11:28 pm

    Modify your last statement to return a pointer to the resulting b2Fixture object. This can be kept as a class variable (ie. b2Fixture* fixture in your class interface).

    fixture = polyBody->CreateFixture(&fixtureDefPoly);
    

    Then, wherever you want to change the vertices of the polygon shape, grab a pointer to the shape object associated with your fixture:

    b2PolygonShape* shape = (b2PolygonShape*) fixture->GetShape();
    

    And modify the vertices as appropriate:

    shape->m_vertices[0].Set(new_x0/PTM_RATIO,new_y0/PTM_RATIO); 
    shape->m_vertices[1].Set(new_x1/PTM_RATIO,new_y1/PTM_RATIO); 
    shape->m_vertices[2].Set(new_x2/PTM_RATIO,new_y2/PTM_RATIO); 
    ...
    shape->m_vertices[7].Set(new_x7/PTM_RATIO,new_y7/PTM_RATIO); 
    

    Good luck!

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

Sidebar

Related Questions

I am new to cocos2d, In that I want to create a button, by
I am new to cocos2d and im developing my first iphone game. The requirement
I'm new to cocos2D, and I wanna add an object that can be deformed
I'm new to cocos2d and to iphone development at all. I want to create
I am new to Cocos2D and I want to know how to make a
i want to create a new view in Cocos2d programmatically can you help me
I'm new to Cocos2d and am after some help. I have a sprite that
I'm new to cocos2d and my game situation is below. In top-down shooter game
Does anyone know how to install cocos2d so it shows up in the new
I am new to Cocos2D. I am working with a couple of people on

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.