Interface PlatformModels


public interface PlatformModels

3D models for actors in 2.5D (PlatformView#setDepth(boolean)). Without one, depth mode stands each actor up as a flat billboard of its sprite; with one, an actor whose kind has a model is drawn as that skinned glTF model instead, turned to face where it walks and playing the clip its state asks for. The simulation is untouched: the same level and the same replay, drawn with models.

import com.codename1.gaming.platformer.*;
import com.codename1.gaming.platformer.view.*;
import com.codename1.gaming.AnimatedModel;
import com.codename1.gpu.*;

LevelData level = LevelData.parse("{\"tileSize\":16,\"spawn\":[1,1],\"tiles\":[\"........\",\"........\",\"########\"]}");
PlatformView view = new PlatformView(level.createWorld(1), new ProceduralArt(16));
GltfScene heroScene = GltfLoader.loadScene(Display.getInstance().getResourceAsStream(null, "/hero.glb"));
view.setModels(new PlatformModels() {
    public AnimatedModel model(GraphicsDevice d, Actor a) {
        return "hero".equals(a.getKind()) ? new AnimatedModel(d, heroScene) : null;
    }
    public String clip(Actor a) {
        return a.getState() == MovementState.RUNNING ? "Run" : "Idle";
    }
    public float height(Actor a) {
        return 1.1f;
    }
});
  • Method Summary

    Modifier and Type
    Method
    Description
    clip(Actor actor)
    The animation clip for an actor's current state.
    float
    height(Actor actor)
    How tall the model stands, in tiles.
    model(GraphicsDevice device, Actor actor)
    Makes the model for an actor, once per actor.
  • Method Details

    • model

      AnimatedModel model(GraphicsDevice device, Actor actor)

      Makes the model for an actor, once per actor. Called on the render thread after the GPU device exists.

      Parameters
      • device: the device the model will draw on
      • actor: the actor; Actor#getKind() says which model
      Returns

      a new model, or null to keep the billboard for this actor

    • clip

      String clip(Actor actor)

      The animation clip for an actor's current state.

      Parameters
      • actor: the actor
      Returns

      a clip name in the model's scene, or null to keep the current one

    • height

      float height(Actor actor)

      How tall the model stands, in tiles. The model is scaled so its bounds are this tall and placed standing on the actor's feet.

      Parameters
      • actor: the actor
      Returns

      the height in tiles