In regards to this question I am finding some problems.
I recieve this error "1151: A conflict exists with definition body in namespace internal" with this code
Code:
var body:b2Body = myWorld.CreateBody(bodyDef);
Here is the rest of my code. "m_sprite" is the name of a Movie Clip object I am trying apply physics to.
Code:
import Box2D.Dynamics.*; // physics
import Box2D.Collision.*; // bounding box
import Box2D.Collision.Shapes.*; // define shapes
import Box2D.Common.Math.*; // for vector
import flash.display.*; // sprite class
var worldBox:b2AABB = new b2AABB();
var body:m_sprite;
worldBox.lowerBound.Set(-100,-100) // 1m = 30pixels
worldBox.upperBound.Set(50,50);
bodyDef.userData = new m_sprite();
// gravity
var gravity:b2Vec2 = new b2Vec2(0, 10) // 300 pixels / per second sqaured
var bSleep:Boolean = true;
var myWorld:b2World = new b2World(worldBox, gravity, bSleep);
// Box
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.SetAsBox(3,1); // 1 meter = 30 pixels, width 90, height 30
boxDef.friction = 0.3 // between 0 and 1
boxDef.density = 0.5;
var bodyDef:b2BodyDef = new m_sprite();
bodyDef.userData = new Sprite();
bodyDef.userData.width = 90;
bodyDef.userData.height = 30;
bodyDef.position.Set(13, 10) // x = 165, y = 300
addChild(bodyDef.userData);
var body:b2Body = myWorld.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
// debug draw
var dbgDraw:b2DebugDraw = new b2DebugDraw();
dbgDraw.m_sprite = new Sprite();
addChild(dbgDraw.m_sprite);
dbgDraw.m_drawScale = 30.0;
dbgDraw.m_fillAlpha - 0.3;
dbgDraw.m_lineThickness = 1.0;
dbgDraw.m_drawFlags = b2DebugDraw.e_shapeBit;
myWorld.SetDebugDraw(dbgDraw);
var m_timeStep:Number = 1.0 / 24.0; // (1.0) steps per frame
var m_iterations:int = 10;
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
function Update(e:Event):void{
myWorld.Step(m_timeStep, m_iterations);
}
Could you possibly run down a little sample code explaining basically how you would add a Movie Clip object too?