Package com.deco2800.game.physics
Class PhysicsEngine
java.lang.Object
com.deco2800.game.physics.PhysicsEngine
- All Implemented Interfaces:
Disposable
public class PhysicsEngine extends java.lang.Object implements Disposable
Process game physics using the Box2D library. See the Box2D documentation for examples or use
cases.
-
Constructor Summary
Constructors Constructor Description PhysicsEngine()PhysicsEngine(World world, GameTime timeSource) -
Method Summary
Modifier and Type Method Description BodycreateBody(BodyDef bodyDef)JointcreateJoint(JointDef jointDef)voiddestroyBody(Body body)voiddestroyJoint(Joint joint)voiddispose()WorldgetWorld()booleanraycast(Vector2 from, Vector2 to, short layerMask, RaycastHit hit)Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.booleanraycast(Vector2 from, Vector2 to, RaycastHit hit)Cast a ray in a straight line from one point to another, checking for a collision against any colliders.RaycastHit[]raycastAll(Vector2 from, Vector2 to)Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.RaycastHit[]raycastAll(Vector2 from, Vector2 to, short layerMask)Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.voidupdate()
-
Constructor Details
-
PhysicsEngine
public PhysicsEngine() -
PhysicsEngine
-
-
Method Details
-
update
public void update() -
createBody
-
destroyBody
-
createJoint
-
destroyJoint
-
getWorld
-
raycast
Cast a ray in a straight line from one point to another, checking for a collision against any colliders.- Parameters:
from- The starting point of the ray.to- The end point of the ray.hit- The raycast result will be stored in this class- Returns:
- true if a collider was hit, false otherwise.
-
raycast
Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.- Parameters:
from- The starting point of the ray.to- The end point of the ray.hit- The hit of the closest collider will be stored in this.layerMask- The physics layer mask which specifies layers that can be hit. Other layers will be ignored.- Returns:
- true if a collider was hit, false otherwise.
-
raycastAll
Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.- Parameters:
from- The starting point of the ray.to- The end point of the ray.- Returns:
- All hits made by the ray, unordered. Empty if no hits were made.
-
raycastAll
Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.- Parameters:
from- The starting point of the ray.to- The end point of the ray.layerMask- The physics layer mask which specifies layers that can be hit. Other layers will be ignored.- Returns:
- All hits made by the ray, unordered. Empty if no hits were made.
-
dispose
public void dispose()- Specified by:
disposein interfaceDisposable
-