hay
i'm building a platformGame in box2D, i would like to add some revolute joint. but do i have to modify my actor below to handle this joint?
i have no experience with joints in box2d so i hoop someone can help
actor
revolute joint actor
i'm building a platformGame in box2D, i would like to add some revolute joint. but do i have to modify my actor below to handle this joint?
i have no experience with joints in box2d so i hoop someone can help
actor
Code:
public function Actor(myBody:b2Body, myGraphic:DisplayObject)
{
_body = myBody;
_body.SetUserData(this);
_graphic = myGraphic;
trace (_graphic);
updateMyLook();
}
protected function childSpecificUpdating():void
{
/// this funtion does nothing
/// to be call by the childeren
}
///remove actor from the world
public function destroy():void
{
///remove event listener, cleanup
cleanUpBeforeRemoving();
//remove the the graphic from the disply
_graphic.parent.removeChild(_graphic);
//destroy the body
PhysiVals.world.DestroyBody(_body);
}
public function cleanUpBeforeRemoving():void
{
/// this funtion does nothing
/// to be call by the childeren
}
public function updateNow():void
{
//save cpu if not all body are updated
//wil geve a problem when static object are move scprite weis
//if (!_body.IsStatic())
//{
updateMyLook();
childSpecificUpdating();
//}
}
private function updateMyLook():void
{
/*Following code down to line 252 Makes the Player move left, right and jump*/
//trace (getChildByName "HERO");
//update the graphic to box2d body
_graphic.x = _body.GetPosition().x * PhysiVals.RATIO;
_graphic.y = _body.GetPosition().y * PhysiVals.RATIO;
_graphic.rotation = _body.GetAngle() * 180 / Math.PI;
}
}
{
_body = myBody;
_body.SetUserData(this);
_graphic = myGraphic;
trace (_graphic);
updateMyLook();
}
protected function childSpecificUpdating():void
{
/// this funtion does nothing
/// to be call by the childeren
}
///remove actor from the world
public function destroy():void
{
///remove event listener, cleanup
cleanUpBeforeRemoving();
//remove the the graphic from the disply
_graphic.parent.removeChild(_graphic);
//destroy the body
PhysiVals.world.DestroyBody(_body);
}
public function cleanUpBeforeRemoving():void
{
/// this funtion does nothing
/// to be call by the childeren
}
public function updateNow():void
{
//save cpu if not all body are updated
//wil geve a problem when static object are move scprite weis
//if (!_body.IsStatic())
//{
updateMyLook();
childSpecificUpdating();
//}
}
private function updateMyLook():void
{
/*Following code down to line 252 Makes the Player move left, right and jump*/
//trace (getChildByName "HERO");
//update the graphic to box2d body
_graphic.x = _body.GetPosition().x * PhysiVals.RATIO;
_graphic.y = _body.GetPosition().y * PhysiVals.RATIO;
_graphic.rotation = _body.GetAngle() * 180 / Math.PI;
}
}
revolute joint actor
Code:
public function LevelFourPivotActor(parent:DisplayObjectContainer,$levelFourPivotGraphic, leftBounds:int, rightBounds:int, yPos:int)
{
trace("hello");
///create the levelthree graphic
_levelFourPivotGraphic = $levelFourPivotGraphic;
parent.addChild (_levelFourPivotGraphic);// set graphic for level zoro
var pivot:b2BodyDef = new b2BodyDef();
pivot.position.Set(0, 0);
var pivotPoly:b2PolygonDef = new b2PolygonDef();
pivotPoly.SetAsBox(1,1);
pivotPoly.density = 0;
var pivotBody:b2Body = PhysiVals.world.CreateBody(pivot);
pivotBody.CreateShape(pivotPoly)
pivotBody.SetMassFromShapes();
var motorPoly:b2PolygonDef = new b2PolygonDef();
motorPoly.SetAsOrientedBox(30, 10, new b2Vec2(0, 0), 0);
motorPoly.friction = .3;
motorPoly.density = .01;
motorPoly.restitution = .1;
var motorDef:b2BodyDef = new b2BodyDef();
motorDef.position.Set(110, 250);
var motorBody:b2Body = PhysiVals.world.CreateBody(motorDef);
motorBody.CreateShape(motorPoly);
motorBody.SetMassFromShapes();
var rjd:b2RevoluteJointDef = new b2RevoluteJointDef();
//Setup the revolute joint definition for later instantiation. rjd is a predefined b2RevoluteJointDef object.
rjd.Initialize(pivotBody, motorBody, new b2Vec2(80,250));
rjd.motorSpeed = 3;
rjd.maxMotorTorque = 10000000;
rjd.enableMotor = true;
rjd.enableLimit = false;
//Create the motor joint and cast it as a b2RevoluteJoint
var joint1:b2RevoluteJoint = PhysiVals.world.CreateJoint(rjd) as b2RevoluteJoint;
super (joint1, _levelFourPivotGraphic);
SetMyMovieFrame();
}
override protected function childSpecificUpdating():void
{
}
}
{
trace("hello");
///create the levelthree graphic
_levelFourPivotGraphic = $levelFourPivotGraphic;
parent.addChild (_levelFourPivotGraphic);// set graphic for level zoro
var pivot:b2BodyDef = new b2BodyDef();
pivot.position.Set(0, 0);
var pivotPoly:b2PolygonDef = new b2PolygonDef();
pivotPoly.SetAsBox(1,1);
pivotPoly.density = 0;
var pivotBody:b2Body = PhysiVals.world.CreateBody(pivot);
pivotBody.CreateShape(pivotPoly)
pivotBody.SetMassFromShapes();
var motorPoly:b2PolygonDef = new b2PolygonDef();
motorPoly.SetAsOrientedBox(30, 10, new b2Vec2(0, 0), 0);
motorPoly.friction = .3;
motorPoly.density = .01;
motorPoly.restitution = .1;
var motorDef:b2BodyDef = new b2BodyDef();
motorDef.position.Set(110, 250);
var motorBody:b2Body = PhysiVals.world.CreateBody(motorDef);
motorBody.CreateShape(motorPoly);
motorBody.SetMassFromShapes();
var rjd:b2RevoluteJointDef = new b2RevoluteJointDef();
//Setup the revolute joint definition for later instantiation. rjd is a predefined b2RevoluteJointDef object.
rjd.Initialize(pivotBody, motorBody, new b2Vec2(80,250));
rjd.motorSpeed = 3;
rjd.maxMotorTorque = 10000000;
rjd.enableMotor = true;
rjd.enableLimit = false;
//Create the motor joint and cast it as a b2RevoluteJoint
var joint1:b2RevoluteJoint = PhysiVals.world.CreateJoint(rjd) as b2RevoluteJoint;
super (joint1, _levelFourPivotGraphic);
SetMyMovieFrame();
}
override protected function childSpecificUpdating():void
{
}
}