Class ProceduralArt

java.lang.Object
com.codename1.gaming.platformer.view.ProceduralArt
All Implemented Interfaces:
PlatformArt

public class ProceduralArt extends Object implements PlatformArt

Art drawn from code: flat tiles with a lit top edge, rounded characters with eyes and stepping feet, coins, keys, doors and springs. Every image is made once and cached.

It makes a level playable and readable before any art exists, and it is the fallback a game keeps for whatever it has not drawn yet: extend it and override #tile, #sheet or #entity for the kinds you have art for. The palette is set with #setPalette.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Frames in a generated actor sheet: 0-1 idle, 2-5 walk, 6 jump, 7 fall, 8 crouch, 9 climb, 10 hurt, 11 dash.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ProceduralArt(int tileSize)
    Creates the art for a tile size.
  • Method Summary

    Modifier and Type
    Method
    Description
    animator(Actor actor)
    The animator for an actor.
    protected int
    colorFor(Actor actor)
    The body color for an actor: the hero is the accent, others are derived from the kind name.
    entity(LevelEntity e, int tick)
    The image for an entity this tick.
    protected int
    The tile size.
    goal(int width, int height, int tick)
    The image for the level's goal this tick, drawn centered on the goal rectangle (PlatformWorld#getGoal()).
    The image for a moving platform.
    void
    setPalette(int ground, int groundTop, int accent)
    Sets the colors.
    sheet(Actor actor)
    The sprite sheet for an actor; frames are chosen by #animator(Actor).
    tile(TileGrid grid, int col, int row)
    The image for one cell.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FRAMES

      public static final int FRAMES
      Frames in a generated actor sheet: 0-1 idle, 2-5 walk, 6 jump, 7 fall, 8 crouch, 9 climb, 10 hurt, 11 dash.
      See Also:
  • Constructor Details

    • ProceduralArt

      public ProceduralArt(int tileSize)

      Creates the art for a tile size.

      Parameters
      • tileSize: pixels per tile
  • Method Details

    • setPalette

      public void setPalette(int ground, int groundTop, int accent)

      Sets the colors.

      Parameters
      • ground: solid tiles
      • groundTop: the lit top edge of solid tiles
      • accent: coins and highlights
    • getTileSize

      protected int getTileSize()

      The tile size.

      Returns

      pixels

    • tile

      public Image tile(TileGrid grid, int col, int row)
      Description copied from interface: PlatformArt

      The image for one cell. Called when the view first draws a cell and again whenever the cell changes (a door opening, a block crumbling).

      Parameters
      • grid: the grid, to look at neighbors for auto-tiling
      • col: the column
      • row: the row
      Returns

      an image the size of a tile in pixels, or null to draw nothing

      Specified by:
      tile in interface PlatformArt
    • sheet

      public SpriteSheet sheet(Actor actor)
      Description copied from interface: PlatformArt

      The sprite sheet for an actor; frames are chosen by #animator(Actor). The frame is drawn centered on the body horizontally and standing on its bottom edge, so a sheet may be larger than the body.

      Parameters
      • actor: the actor; Actor#getKind() names its art
      Returns

      the sheet

      Specified by:
      sheet in interface PlatformArt
    • colorFor

      protected int colorFor(Actor actor)

      The body color for an actor: the hero is the accent, others are derived from the kind name.

      Parameters
      • actor: the actor
      Returns

      RGB

    • animator

      public ActorAnimator animator(Actor actor)
      Description copied from interface: PlatformArt

      The animator for an actor.

      Parameters
      • actor: the actor
      Returns

      the animator, typically shared by every actor of a kind

      Specified by:
      animator in interface PlatformArt
    • entity

      public Image entity(LevelEntity e, int tick)
      Description copied from interface: PlatformArt

      The image for an entity this tick. Called every tick, so return cached images.

      Parameters
      • entity: the entity; LevelEntity#getType() and LevelEntity#getPhase() select the image
      • tick: the world tick, for animating
      Returns

      the image, drawn centered on the entity, or null to draw nothing

      Specified by:
      entity in interface PlatformArt
    • platform

      public Image platform(MovingPlatform p)
      Description copied from interface: PlatformArt

      The image for a moving platform.

      Parameters
      • platform: the platform
      Returns

      an image the platform's size in pixels

      Specified by:
      platform in interface PlatformArt
    • goal

      public Image goal(int width, int height, int tick)
      Description copied from interface: PlatformArt

      The image for the level's goal this tick, drawn centered on the goal rectangle (PlatformWorld#getGoal()).

      Parameters
      • width: the goal's width in pixels
      • height: the goal's height in pixels
      • tick: the world tick, for animating
      Returns

      the image, or null to draw nothing

      Specified by:
      goal in interface PlatformArt