public class AssetDef

  1. Object
  2. AssetDef

The definition of one placeable asset in an AssetPack: the template a placed GameElement references through its GameElement#getAssetId().

It mirrors an entry in the editor’s asset catalog – an id, a display name, a #getKind() (a Kind#TILE painted into a grid cell vs a freely placed Kind#ACTOR), a natural pixel size, a base #getColor() (used to render a placeholder until the real art loads), whether the level may hold more than one (#isUnique()), the default authoring properties copied onto a freshly placed element, and – the part that makes it a real asset – a #getType() and a #getSource() art file:

  • Type#IMAGE – a single static image (source is a PNG/JPG path), realized as a com.codename1.gaming.Sprite.
  • Type#SHEET – a sprite sheet: an image of equal frames in a grid (#getFrameWidth() x #getFrameHeight(), #getFps()), realized as an animated com.codename1.gaming.AnimatedSprite.
  • Type#MESH – a 3D mesh (source is a glTF/glb path), realized as a com.codename1.gaming.Model in a 3D level.

Nested types

enum AssetDef.KindHow an asset is placed: painted into a grid cell, or freely positioned.
enum AssetDef.TypeThe art format of an asset, which decides what it is realized into.

Constructors

public AssetDef()
public AssetDef(String id, AssetDef.Kind kind, int color, int width, int height)

Methods

public String getId()
public AssetDef setId(String id)
public String getName()
public AssetDef setName(String name)
public AssetDef.Kind getKind()How this asset is placed (Kind#TILE vs Kind#ACTOR).
public AssetDef setKind(AssetDef.Kind kind)
public boolean isTile()
public int getWidth()
public int getHeight()
public AssetDef setSize(int width, int height)
public int getColor()
public AssetDef setColor(int color)
public boolean isUnique()
public AssetDef setUnique(boolean unique)
public String getSource()
public AssetDef setSource(String source)
public AssetDef.Type getType()The art format: Type#IMAGE, Type#SHEET or Type#MESH.
public AssetDef setType(AssetDef.Type type)
public boolean isSheet()
public boolean isMesh()
public int getFrameWidth()Sprite-sheet frame width in pixels (0 = the whole image is one frame).
public int getFrameHeight()Sprite-sheet frame height in pixels (0 = the whole image is one frame).
public int getFrameCount()Number of frames to play (0 = every frame in the sheet).
public double getFps()Sprite-sheet playback rate in frames per second.
public AssetDef setSheet(int frameWidth, int frameHeight, int frameCount, double fps)Marks this asset as a sprite sheet with the given frame grid and rate.
public Map<String, Object> defaultProperties()The default authoring properties copied onto a newly placed element of this asset (a coin’s value, a player’s lives, …).
public AssetDef putDefault(String key, Object value)

Inherited methods

Constructor details

AssetDef

public AssetDef()

AssetDef

public AssetDef(String id, AssetDef.Kind kind, int color, int width, int height)

Method details

getId

public String getId()

setId

public AssetDef setId(String id)

getName

public String getName()

setName

public AssetDef setName(String name)

getKind

public AssetDef.Kind getKind()
How this asset is placed (Kind#TILE vs Kind#ACTOR).

setKind

public AssetDef setKind(AssetDef.Kind kind)

isTile

public boolean isTile()

getWidth

public int getWidth()

getHeight

public int getHeight()

setSize

public AssetDef setSize(int width, int height)

getColor

public int getColor()

setColor

public AssetDef setColor(int color)

isUnique

public boolean isUnique()

setUnique

public AssetDef setUnique(boolean unique)

getSource

public String getSource()

setSource

public AssetDef setSource(String source)

getType

public AssetDef.Type getType()
The art format: Type#IMAGE, Type#SHEET or Type#MESH.

setType

public AssetDef setType(AssetDef.Type type)

isSheet

public boolean isSheet()

isMesh

public boolean isMesh()

getFrameWidth

public int getFrameWidth()
Sprite-sheet frame width in pixels (0 = the whole image is one frame).

getFrameHeight

public int getFrameHeight()
Sprite-sheet frame height in pixels (0 = the whole image is one frame).

getFrameCount

public int getFrameCount()
Number of frames to play (0 = every frame in the sheet).

getFps

public double getFps()
Sprite-sheet playback rate in frames per second.

setSheet

public AssetDef setSheet(int frameWidth, int frameHeight, int frameCount, double fps)
Marks this asset as a sprite sheet with the given frame grid and rate.

defaultProperties

public Map<String, Object> defaultProperties()
The default authoring properties copied onto a newly placed element of this asset (a coin’s value, a player’s lives, …).

putDefault

public AssetDef putDefault(String key, Object value)