Box2D Forums

It is currently Thu May 23, 2013 2:50 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Scaling circule
PostPosted: Fri Sep 17, 2010 3:28 pm 
Offline

Joined: Tue Jul 06, 2010 11:23 am
Posts: 11
Hi,

I'm working with the latest Box2d for flash version, and I'm trying to scale a circle shape in a body (make it smaller in each frame)

I'm looking at this example:
http://www.emanueleferonato.com/2009/12/12/scaling-objects-with-box2d/

But I don't understand how to use it with the newer version.

I'v tried:
Code:
override protected function updateMyLook():void
      {
         var circ:b2CircleShape = this._body.GetFixtureList() as b2CircleShape;
         var r = circ.GetRadius();         
         this._body.DestroyFixture(circ);
         
         var bBodyShape:b2CircleShape = new b2CircleShape(((r * PhysicsVars.RATIO) - 1) / PhysicsVars.RATIO);
         
         var bBodyFixtureDef:b2FixtureDef = new b2FixtureDef();
         bBodyFixtureDef.shape = bBodyShape;
         bBodyFixtureDef.density = 0;
         bBodyFixtureDef.friction = 0;
         bBodyFixtureDef.restitution = 0.5;
         bBodyFixtureDef.isSensor = false; // setting as sensor for collusions
         this._body.CreateFixture(bBodyFixtureDef);
         super.updateMyLook();
      }


but then I cant destroy circ since it is not a fixture. If I'm trying to take fixture from the list, I wouldn't be able to get radius.

can someone show me an example, of how it should be done?

Thanks, Shefy


Top
 Profile  
 
PostPosted: Sat Sep 18, 2010 2:51 am 
Offline

Joined: Tue Jul 06, 2010 11:23 am
Posts: 11
It took me some time, but I found the solution - hope it would help someone (please tell me if so)

Code:

      override protected function updateMyLook():void
      {
         
         var circF:b2Fixture = this._body.GetFixtureList() as b2Fixture;
         var circ:b2CircleShape = circF.GetShape() as b2CircleShape;
         var r = circ.GetRadius();
         this._body.DestroyFixture(circF);
         
         var bBodyShape:b2CircleShape = new b2CircleShape(((r * PhysicsVars.RATIO) - 0.03) / PhysicsVars.RATIO);
         
         var bBodyFixtureDef:b2FixtureDef = new b2FixtureDef();
         bBodyFixtureDef.shape = bBodyShape;
         bBodyFixtureDef.density = 0;
         bBodyFixtureDef.friction = 0;
         bBodyFixtureDef.restitution = 0.5;
         bBodyFixtureDef.isSensor = false; // setting as sensor for collusions
         this._body.CreateFixture(bBodyFixtureDef);
         
         _body.GetAngularVelocity()
         
         super.updateMyLook();
      }


Thanks Shefy


Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sat Sep 18, 2010 8:24 am 
Offline

Joined: Mon Sep 13, 2010 8:36 am
Posts: 10
I had a similar question a few days ago - I'm using the Alchemy port, but I assume things work the same at the Box2D level.

In my case it was sufficient to simply change the radius of the shape instead of creating a new fixture:

Code:
         var circF:b2Fixture = this._body.GetFixtureList() as b2Fixture;
         var circ:b2CircleShape = circF.GetShape() as b2CircleShape;
         var r:Number = circ.m_radius;
         circ.m_radius = ((r * PhysicsVars.RATIO) - 0.03) / PhysicsVars.RATIO;


Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sat Sep 18, 2010 9:00 am 
Offline

Joined: Tue Jul 06, 2010 11:23 am
Posts: 11
10x - Trying it now.

In my version - I would have to use setRadius(r) - since m_radius is now no longer public.

What is Alchemy?


Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sat Sep 18, 2010 9:35 am 
Offline

Joined: Tue Jul 06, 2010 11:23 am
Posts: 11
Great - it worked :)

Which means that what is shown in the tutorial is an overkill.

Still would loveto know - What is Alchemy?


Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sat Sep 18, 2010 12:55 pm 
Offline

Joined: Mon Sep 13, 2010 8:36 am
Posts: 10
http://www.sideroller.com/wck/

Adobe Alchemy is a C++ compiler that targets the Flash VM. mayobutter ported the original Box2D C++ to Flash using Alchemy (and a lot of elbow grease, apparently)


Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sat Sep 18, 2010 1:30 pm 
Offline

Joined: Tue Jul 06, 2010 11:23 am
Posts: 11
interesting. Can you show what you were working on?


Thanks for your help, I put a link to this thread in the comments on the tutorial page I started from - maybe we could help more people.
There are almost no tutorials on the latest Box2d for flash, and they changed quite a bit.


Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sun Sep 19, 2010 9:41 pm 
Offline

Joined: Mon Sep 13, 2010 8:36 am
Posts: 10
Here's my proof-of-concept for frothy bubbles. Mostly just playing around right now, trying out different things.

I am developing with FlashDevelop, so there is no .fla file. I'm just including the 3 source files. Since it uses the Alchemy port you'll have to grab that too from http://github.com/jesses/wck, or modify it to build with the Flash port.


Attachments:
BubbleTest.zip [2.5 KiB]
Downloaded 98 times
Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Sun Sep 19, 2010 11:50 pm 
Offline

Joined: Tue Jul 06, 2010 11:23 am
Posts: 11
Nice.

I'm attaching something I did as an experiment for a game I'm working on.

have a look on the Actor class and how I'm using it, I think it might be helpful, this is something I learned from Todd Tutorial on making peggle look alike:

http://www.kerp.net/box2d/

Again - 10x 4 your help


Attachments:
File comment: All but the fla file
FallingTrianglesTry.rar [74.52 KiB]
Downloaded 98 times
Top
 Profile  
 
 Post subject: Re: Scaling circule
PostPosted: Fri Mar 25, 2011 10:32 am 
Offline

Joined: Fri Mar 25, 2011 8:04 am
Posts: 2
Hi,
I'm new to box2d and I encountered this scaling problem too.

May i know where do i put the codes for creating and deleting of the bodies? This is because i just create the bodies by referencing it using the movieclip i created.
Kindly advice me as i quite confused.

Many thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group