# Class AssetDef

java.lang.Object
com.codename1.gaming.level.AssetDef

public class AssetDef extends Object

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 Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `AssetDef.Kind`
  How an asset is placed: painted into a grid cell, or freely positioned.
  `static enum`
  `AssetDef.Type`
  The art format of an asset, which decides what it is realized into.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AssetDef()`
  `AssetDef(String id, AssetDef.Kind kind, int color, int width, int height)`

- ## Method Summary

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

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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)