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()
Sets up the base values of the RigidBody componentRigidBody(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 void
addTrigger(float radius, java.lang.Object data)
Adds a new circular fixture to the body as a triggervoid
applyForce(com.badlogic.gdx.math.Vector2 force)
float
getAngularVelocity()
com.badlogic.gdx.physics.box2d.Body
getBody()
com.badlogic.gdx.math.Vector2
getPosition()
Gets the current player position.com.badlogic.gdx.math.Vector2
getVelocity()
void
setCallback(CollisionCallBack data)
Is used during collision phase to add more functionalityvoid
setPosition(com.badlogic.gdx.math.Vector2 position)
Sets the center pos of the objectvoid
setVelocity(float x, float y)
void
setVelocity(com.badlogic.gdx.math.Vector2 vel)
void
update()
Called every frame translates the transform to match with the box2d body's position factoring offset
-
-
-
Constructor Detail
-
RigidBody
public RigidBody()
Sets up the base values of the RigidBody component
-
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
-
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
-
getPosition
public com.badlogic.gdx.math.Vector2 getPosition()
Gets the current player position. // Change for Assessment 2 //- Returns:
- player position.
-
getBody
public com.badlogic.gdx.physics.box2d.Body getBody()
- Returns:
- the Body of this object
-
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()
- Returns:
- the Linear Velocity of this object
-
getAngularVelocity
public float getAngularVelocity()
- Returns:
- the Angular Velocity of this object
-
applyForce
public void applyForce(com.badlogic.gdx.math.Vector2 force)
- Parameters:
force
- the force to apply to the center of the object
-
-