Skip to content

Platform

Adi edited this page Aug 31, 2026 · 2 revisions

Platform

public static Entity createPlatform(float width, float height) {
  Entity platform =
      new Entity()
          .addComponent(new TextureRenderComponent("images/platform.png"))
          .addComponent(new PhysicsComponent())
          .addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE));

  platform.getComponent(PhysicsComponent.class).setBodyType(BodyType.StaticBody);
  platform.setScale(width, height);
  return platform;
}

It is used to create a platform entity that the player can stand on. PhysicsComponent and ColliderComponent make it solid, so the player collides with it instead of walking through it. setBodyType(StaticBody) means the platform never moves.

private void spawnPlatform() {
  Entity platform = ObstacleFactory.createPlatform(PLATFORM_WIDTH, PLATFORM_HEIGHT);
  spawnEntityAt(platform, PLATFORM_POS, true, false);
}

It is used to actually place the platform into the forest area. It calls createPlatform() to build the platform, then spawnEntityAt() places it at a fixed position instead of a random one, so it's always in the same spot.

The platform works like the trees and walls already in the game — same physics setup, just wider and visible, so the player has solid ground to stand on.

GridPoint2 minPos = new GridPoint2(0, 4);

It is used to stop trees and ghosts from spawning below or on top of the platform.

private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(4, 4);

To make the player spawn standing on top of the platform

Clone this wiki locally