Package com.mygdx.game.Components
Class RigidBody
- java.lang.Object
-
- com.mygdx.game.Components.Component
-
- com.mygdx.game.Components.RigidBody
-
public class RigidBody extends Component
Defines parameters related to collisions of sprites.
-
-
Field Summary
-
Fields inherited from class com.mygdx.game.Components.Component
parent, reqsMet, requirements, type
-
-
Constructor Summary
Constructors Constructor Description RigidBody()RigidBody(PhysicsBodyType type, Renderable r, Transform t)Calls constructor with is trigger falseRigidBody(PhysicsBodyType type, Renderable r, Transform t, boolean isTrigger)Can create body that is trigger or callable
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTrigger(float radius, java.lang.Object data)Adds a new circular fixture to the body as a triggervoidapplyForce(com.badlogic.gdx.math.Vector2 force)floatgetAngularVelocity()com.badlogic.gdx.physics.box2d.BodygetBody()com.badlogic.gdx.math.Vector2getVelocity()voidremoveFromPhysicsWorld()voidsetCallback(CollisionCallBack data)Is used during collision phase to add more functionalityvoidsetPosition(com.badlogic.gdx.math.Vector2 position)Sets the center pos of the objectvoidsetPosition(com.badlogic.gdx.math.Vector2 position, boolean offset)Sets the bottom left position of the objectvoidsetVelocity(float x, float y)voidsetVelocity(com.badlogic.gdx.math.Vector2 vel)voidupdate()Called every frame translates the transform to match with the box2d body's position factoring offset
-
-
-
Constructor Detail
-
RigidBody
public RigidBody()
-
RigidBody
public RigidBody(PhysicsBodyType type, Renderable r, Transform t)
Calls constructor with is trigger false- Parameters:
type- defines how it interacts with other objectsr- used for creating the fixture (aka the collider)t- used for positioning and scaling the collider
-
RigidBody
public RigidBody(PhysicsBodyType type, Renderable r, Transform t, boolean isTrigger)
Can create body that is trigger or callable- Parameters:
type- defines how it interacts with other objectsr- used for creating the fixture (aka the collider)t- used for positioning and scaling the colliderisTrigger- false allows for collision true doesn't
-
-
Method Detail
-
removeFromPhysicsWorld
public void removeFromPhysicsWorld()
-
addTrigger
public void addTrigger(float radius, java.lang.Object data)Adds a new circular fixture to the body as a trigger
-
setCallback
public void setCallback(CollisionCallBack data)
Is used during collision phase to add more functionality- Parameters:
data- class that inherits from CollisionCallBack
-
setVelocity
public void setVelocity(com.badlogic.gdx.math.Vector2 vel)
-
setVelocity
public void setVelocity(float x, float y)
-
setPosition
public void setPosition(com.badlogic.gdx.math.Vector2 position)
Sets the center pos of the object
-
setPosition
public void setPosition(com.badlogic.gdx.math.Vector2 position, boolean offset)Sets the bottom left position of the object- Parameters:
offset- should plly offset
-
getBody
public com.badlogic.gdx.physics.box2d.Body getBody()
-
update
public void update()
Called every frame translates the transform to match with the box2d body's position factoring offset
-
getVelocity
public com.badlogic.gdx.math.Vector2 getVelocity()
-
getAngularVelocity
public float getAngularVelocity()
-
applyForce
public void applyForce(com.badlogic.gdx.math.Vector2 force)
-
-