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
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()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 offsetMethods inherited from class com.mygdx.game.Components.Component
awake, cleanUp, getParent, getType, render, setParent, setRequirements, startMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
RigidBody
public RigidBody() -
RigidBody
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
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 Details
-
addTrigger
public void addTrigger(float radius, java.lang.Object data)Adds a new circular fixture to the body as a trigger -
setCallback
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)
-