Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class ProceduralArt

  1. Object
  2. ProceduralArt

ImplementsPlatformArt

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.

Fields

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

Constructors

public ProceduralArt(int tileSize)Creates the art for a tile size.

Methods

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

Inherited methods

Field details

FRAMES

public static final int FRAMES = 12
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 details

ProceduralArt

public ProceduralArt(int tileSize)
Creates the art for a tile size.

Parameters

tileSize int
pixels per tile

Method details

setPalette

public void setPalette(int ground, int groundTop, int accent)
Sets the colors.

Parameters

ground int
solid tiles
groundTop int
the lit top edge of solid tiles
accent int
coins and highlights

getTileSize

protected int getTileSize()
The tile size.

Returns

pixels

tile

public Image tile(TileGrid grid, int col, int row)
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 TileGrid
the grid, to look at neighbors for auto-tiling
col int
the column
row int
the row

Returns

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

sheet

public SpriteSheet sheet(Actor actor)
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 Actor
the actor; Actor#getKind() names its art

Returns

the sheet

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 Actor
the actor

Returns

RGB

animator

public ActorAnimator animator(Actor actor)
The animator for an actor.

Parameters

actor Actor
the actor

Returns

the animator, typically shared by every actor of a kind

entity

public Image entity(LevelEntity e, int tick)
The image for an entity this tick. Called every tick, so return cached images.

Parameters

e LevelEntity
the entity; LevelEntity#getType() and LevelEntity#getPhase() select the image
tick int
the world tick, for animating

Returns

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

platform

public Image platform(MovingPlatform p)
The image for a moving platform.

Parameters

p MovingPlatform
the platform

Returns

an image the platform’s size in pixels

goal

public Image goal(int width, int height, int tick)
The image for the level’s goal this tick, drawn centered on the goal rectangle (PlatformWorld#getGoal()).

Parameters

width int
the goal’s width in pixels
height int
the goal’s height in pixels
tick int
the world tick, for animating

Returns

the image, or null to draw nothing