Hey,
I checked the testbed in order to setup a buoyancy effect.
I thought the next 4 lines were all that I need:
but nevertheless I cannot make it work in my class.
The full code:
What am I missing? 😳
I checked the testbed in order to setup a buoyancy effect.
I thought the next 4 lines were all that I need:
Code:
var be:b2BuoyancyEffect = new b2BuoyancyEffect();
be.density = 1.5;
be.offset = -300 / Constants.RATIO;
var c:b2Controller = new b2Controller(Constants._myWorld, be, true);
be.density = 1.5;
be.offset = -300 / Constants.RATIO;
var c:b2Controller = new b2Controller(Constants._myWorld, be, true);
but nevertheless I cannot make it work in my class.
The full code:
Code:
package
{
import Box2DAS.Dynamics.Joints.b2RevoluteJoint;
import Box2DAS.Dynamics.Joints.b2RevoluteJointDef;
import Box2DAS.Dynamics.Joints.b2JointDef;
import Box2DAS.Controllers.b2Controller;
import Box2DAS.Controllers.b2BuoyancyEffect;
import Box2DAS.Dynamics.b2DebugDraw;
import Box2DAS.Collision.Shapes.b2PolygonShape;
import Box2DAS.Dynamics.b2Body;
import Box2DAS.Common.b2Def;
import Box2DAS.Dynamics.b2World;
import Physics.Constants;
import Box2DAS.Common.V2;
import flash.events.Event;
import flash.display.Sprite;
public class Anwsi extends Sprite
{
private var swma:b2Body;
private var swma2:b2Body;
public var debug:b2DebugDraw;
private var k:b2RevoluteJoint;
public function Anwsi()
{
setupWorld();
createBody();
createPhysicsDebug();
activateAnwsi();
addEventListener(Event.ENTER_FRAME, goWorld);
}
private function createPhysicsDebug() : void
{
debug = new b2DebugDraw();
addChild(debug);
}
private function setupWorld() : void
{
var gravity:V2 = new V2(0.0,9.0);
var doSleep:Boolean = true;
Constants._myWorld=new b2World(gravity,doSleep);
}
private function createBody() : void
{
b2Def.body.type = b2Body.b2_dynamicBody;
b2Def.fixture.shape = new b2PolygonShape();
b2PolygonShape(b2Def.fixture.shape).SetAsBox(50 / Constants.RATIO, 50 / Constants.RATIO);
b2Def.fixture.density = 1;
swma2 = Constants._myWorld.CreateBody(b2Def.body);
swma2.CreateFixture(b2Def.fixture);
swma2.SetTransform(new V2(300/30, 250/30), 0);
}
private function activateAnwsi() : void
{
var be:b2BuoyancyEffect = new b2BuoyancyEffect();
be.density = 1.5;
be.offset = -300 / Constants.RATIO;
var c:b2Controller = new b2Controller(Constants._myWorld, be, true);
}
private function goWorld(event : Event) : void
{
Constants._myWorld.Step(1/60, 10,10);
Constants._myWorld.ClearForces();
debug.graphics.clear();
debug.world = Constants._myWorld;
debug.scale = Constants.RATIO;
debug.Draw();
}
}
}
{
import Box2DAS.Dynamics.Joints.b2RevoluteJoint;
import Box2DAS.Dynamics.Joints.b2RevoluteJointDef;
import Box2DAS.Dynamics.Joints.b2JointDef;
import Box2DAS.Controllers.b2Controller;
import Box2DAS.Controllers.b2BuoyancyEffect;
import Box2DAS.Dynamics.b2DebugDraw;
import Box2DAS.Collision.Shapes.b2PolygonShape;
import Box2DAS.Dynamics.b2Body;
import Box2DAS.Common.b2Def;
import Box2DAS.Dynamics.b2World;
import Physics.Constants;
import Box2DAS.Common.V2;
import flash.events.Event;
import flash.display.Sprite;
public class Anwsi extends Sprite
{
private var swma:b2Body;
private var swma2:b2Body;
public var debug:b2DebugDraw;
private var k:b2RevoluteJoint;
public function Anwsi()
{
setupWorld();
createBody();
createPhysicsDebug();
activateAnwsi();
addEventListener(Event.ENTER_FRAME, goWorld);
}
private function createPhysicsDebug() : void
{
debug = new b2DebugDraw();
addChild(debug);
}
private function setupWorld() : void
{
var gravity:V2 = new V2(0.0,9.0);
var doSleep:Boolean = true;
Constants._myWorld=new b2World(gravity,doSleep);
}
private function createBody() : void
{
b2Def.body.type = b2Body.b2_dynamicBody;
b2Def.fixture.shape = new b2PolygonShape();
b2PolygonShape(b2Def.fixture.shape).SetAsBox(50 / Constants.RATIO, 50 / Constants.RATIO);
b2Def.fixture.density = 1;
swma2 = Constants._myWorld.CreateBody(b2Def.body);
swma2.CreateFixture(b2Def.fixture);
swma2.SetTransform(new V2(300/30, 250/30), 0);
}
private function activateAnwsi() : void
{
var be:b2BuoyancyEffect = new b2BuoyancyEffect();
be.density = 1.5;
be.offset = -300 / Constants.RATIO;
var c:b2Controller = new b2Controller(Constants._myWorld, be, true);
}
private function goWorld(event : Event) : void
{
Constants._myWorld.Step(1/60, 10,10);
Constants._myWorld.ClearForces();
debug.graphics.clear();
debug.world = Constants._myWorld;
debug.scale = Constants.RATIO;
debug.Draw();
}
}
}
What am I missing? 😳