Skip to content

[Feature] Integrate Box2D library to allow usage of advanced physics for expert devs #63

@stringdotjar

Description

@stringdotjar

FlixelObject currently uses a custom physics model (velocity, acceleration, drag, updateMotion(), etc.). The goal is to integrate libGDX’s Box2D via an interface so any subclass (e.g. FlixelSprite) can opt in to Box2D without a separate base class. Implementors get methods like getBody(), createRectangularBody(), etc., with default implementations where possible to reduce boilerplate.

Requirements:

  • Add gdx-box2d to the core module (in flixelgdx-core/build.gradle).
  • Provide an interface (e.g. FlixelBox2DObject) with:
    • Body getBody() (or Optional<Body> if body is created lazily).
    • Convenience defaults (e.g. createRectangularBody(World world) and optionally createRectangularBody(World world, BodyDef def) / fixture helpers) that create a body from the object’s current x, y, width, height, and a documented pixel-to-meter scale, and store it so getBody() returns it. Other helpers (e.g. apply velocity/forces in terms of existing velocityX/velocityY semantics) can be default methods where it makes sense.
  • Do not introduce a dedicated FlixelBox2DSprite (or similar) base class. A dev should be able to extend FlixelSprite (or FlixelObject), implement FlixelBox2DObject, and optionally override defaults.
  • Document (and implement in defaults where applicable) that implementors must sync Box2D body position/angle back to FlixelObject’s x, y and angle (using the same pixel-to-meter scale). If an implementor uses updateMotion(), they can delegate to the world step and then sync from the body instead of the current custom integration.
  • Create a global World object inside of FlixelGame. This is where every object that implements this new interface should be updated. When implemented, there should be static helpers in the Flixel manager class (such as setGravity(float gravity) for example).

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreCore logic module of the frameworkenhancementNew feature or requesthigh priorityMust be completed as soon as possible

    Projects

    Status

    🗒️ Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions