shaku
Version:
A simple and effective JavaScript game development framework that knows its place!
1,200 lines (957 loc) • 425 kB
Markdown

[Back To Table of Content](index.md)
# Shaku
## Classes
<dl>
<dt><a href="#Asset">Asset</a></dt>
<dd><p>A loadable asset base class.
All asset types inherit from this.</p>
</dd>
<dt><a href="#Assets">Assets</a></dt>
<dd><p>Assets manager class.
Used to create, load and cache game assets, which includes textures, audio files, JSON objects, etc.
As a rule of thumb, all methods to load or create assets are async and return a promise.</p>
<p>To access the Assets manager you use <code>Shaku.assets</code>.</p>
</dd>
<dt><a href="#BinaryAsset">BinaryAsset</a></dt>
<dd><p>A loadable binary data asset.
This asset type loads array of bytes from a remote file.</p>
</dd>
<dt><a href="#FontTextureAsset">FontTextureAsset</a></dt>
<dd><p>A font texture asset, dynamically generated from loaded font and canvas.
This asset type creates an atlas of all the font's characters as textures, so we can later render them as sprites.</p>
</dd>
<dt><a href="#JsonAsset">JsonAsset</a></dt>
<dd><p>A loadable json asset.
This asset type loads JSON from a remote file.</p>
</dd>
<dt><a href="#MsdfFontTextureAsset">MsdfFontTextureAsset</a></dt>
<dd><p>A MSDF font texture asset, from a pregenerated msdf texture atlas (from msdf-bmfont-xml, for example).
This asset uses a signed distance field atlas to render characters as sprites at high res.</p>
</dd>
<dt><a href="#SoundAsset">SoundAsset</a></dt>
<dd><p>A loadable sound asset.
This is the asset type you use to play sounds.</p>
</dd>
<dt><a href="#TextureAsset">TextureAsset</a></dt>
<dd><p>A loadable texture asset.
This asset type loads an image from URL or source, and turn it into a texture.</p>
</dd>
<dt><a href="#TextureAssetBase">TextureAssetBase</a></dt>
<dd><p>Base type for all texture asset types.</p>
</dd>
<dt><a href="#TextureAtlasAsset">TextureAtlasAsset</a></dt>
<dd><p>A texture atlas we can build at runtime to combine together multiple textures.</p>
</dd>
<dt><a href="#TextureInAtlasAsset">TextureInAtlasAsset</a></dt>
<dd><p>A texture that is part of a texture atlas.
Stores a texture that was generated by the texture atlas + the source rectangle in texture for this segment.</p>
</dd>
<dt><a href="#Collision">Collision</a></dt>
<dd><p>Collision is the collision manager.
It provides basic 2d collision detection functionality.
Note: this is <em>not</em> a physics engine, its only for detection and objects picking.</p>
<p>To access the Collision manager you use <code>Shaku.collision</code>.</p>
</dd>
<dt><a href="#CollisionWorld">CollisionWorld</a></dt>
<dd><p>A collision world is a set of collision shapes that interact with each other.
You can use different collision worlds to represent different levels or different parts of your game world.</p>
</dd>
<dt><a href="#CollisionResolver">CollisionResolver</a></dt>
<dd><p>The collision resolver is responsible to implement collision detection between pair of shapes of same or different types.</p>
</dd>
<dt><a href="#CollisionTestResult">CollisionTestResult</a></dt>
<dd><p>Collision detection result.</p>
</dd>
<dt><a href="#CircleShape">CircleShape</a></dt>
<dd><p>Collision circle class.</p>
</dd>
<dt><a href="#LinesShape">LinesShape</a></dt>
<dd><p>Collision lines class.
This shape is made of one line or more.</p>
</dd>
<dt><a href="#PointShape">PointShape</a></dt>
<dd><p>Collision point class.</p>
</dd>
<dt><a href="#RectangleShape">RectangleShape</a></dt>
<dd><p>Collision rectangle class.</p>
</dd>
<dt><a href="#CollisionShape">CollisionShape</a></dt>
<dd><p>Collision shape base class.</p>
</dd>
<dt><a href="#TilemapShape">TilemapShape</a></dt>
<dd><p>Collision tilemap class.
A collision tilemap shape is a grid of equal-sized cells that can either block or not (+ have collision flags).
Its the most efficient (both memory and CPU) way to implement grid based / tilemap collision.</p>
</dd>
<dt><a href="#Camera">Camera</a></dt>
<dd><p>Implements a Camera object.</p>
</dd>
<dt><a href="#Camera3D">Camera3D</a></dt>
<dd><p>Implements a 3d Camera object.</p>
</dd>
<dt><a href="#DrawBatch">DrawBatch</a></dt>
<dd><p>Base class for a drawing batch, used to draw a collection of sprites or shapes.</p>
</dd>
<dt><a href="#LinesBatch">LinesBatch</a></dt>
<dd><p>Colored lines renderer.
Responsible to drawing a batch of line segments or strips.</p>
</dd>
<dt><a href="#ShapesBatch">ShapesBatch</a></dt>
<dd><p>Colored shapes renderer.
Responsible to drawing a batch of basic geometric shapes with as little draw calls as possible.</p>
</dd>
<dt><a href="#SpriteBatch">SpriteBatch</a></dt>
<dd><p>Sprite batch renderer.
Responsible to drawing a batch of sprites with as little draw calls as possible.</p>
</dd>
<dt><a href="#SpriteBatch3D">SpriteBatch3D</a></dt>
<dd><p>3D Sprites batch renderer.
Responsible to drawing 3D quads with textures on them.</p>
</dd>
<dt><a href="#SpriteBatchBase">SpriteBatchBase</a></dt>
<dd><p>Base class for sprite-based rendering, ie vertices with textures.</p>
</dd>
<dt><a href="#TextSpriteBatch">TextSpriteBatch</a></dt>
<dd><p>Text sprite batch renderer.
Responsible to drawing a batch of characters sprites.</p>
</dd>
<dt><a href="#Effect">Effect</a></dt>
<dd><p>Effect base class.
An effect = vertex shader + fragment shader + uniforms & attributes + setup code.</p>
</dd>
<dt><a href="#MsdfFontEffect">MsdfFontEffect</a></dt>
<dd><p>Default effect to draw MSDF font textures.</p>
</dd>
<dt><a href="#ShapesEffect">ShapesEffect</a></dt>
<dd><p>Default basic effect to draw 2d shapes.</p>
</dd>
<dt><a href="#SpritesEffect">SpritesEffect</a></dt>
<dd><p>Default basic effect to draw 2d sprites.</p>
</dd>
<dt><a href="#Sprites3dEffect">Sprites3dEffect</a></dt>
<dd><p>Default basic effect to draw 2d sprites.</p>
</dd>
<dt><a href="#SpritesEffectNoVertexColor">SpritesEffectNoVertexColor</a></dt>
<dd><p>Default basic effect to draw 2d sprites without vertex color.</p>
</dd>
<dt><a href="#SpritesWithOutlineEffect">SpritesWithOutlineEffect</a></dt>
<dd><p>Default basic effect to draw 2d sprites with outline.</p>
</dd>
<dt><a href="#Gfx">Gfx</a></dt>
<dd><p>Gfx is the graphics manager.
Everything related to rendering and managing your game canvas goes here.</p>
<p>To access the Graphics manager you use <code>Shaku.gfx</code>.</p>
</dd>
<dt><a href="#Sprite">Sprite</a></dt>
<dd><p>Sprite class.</p>
</dd>
<dt><a href="#SpritesGroup">SpritesGroup</a></dt>
<dd><p>Sprites group class.
This object is a container to hold sprites collection + parent transformations.
You need SpritesGroup to use batched rendering.</p>
</dd>
<dt><a href="#Vertex">Vertex</a></dt>
<dd><p>A vertex we can push to sprite batch.</p>
</dd>
<dt><a href="#Gamepad">Gamepad</a></dt>
<dd><p>Gamepad data object.
This object represents a snapshot of a gamepad state, it does not update automatically.</p>
</dd>
<dt><a href="#FourButtonsCluster">FourButtonsCluster</a></dt>
<dd><p>Buttons cluster container - 4 buttons.</p>
</dd>
<dt><a href="#ThreeButtonsCluster">ThreeButtonsCluster</a></dt>
<dd><p>Buttons cluster container - 3 buttons.</p>
</dd>
<dt><a href="#FrontButtons">FrontButtons</a></dt>
<dd><p>Front buttons.</p>
</dd>
<dt><a href="#Input">Input</a></dt>
<dd><p>Input manager.
Used to recieve input from keyboard and mouse.</p>
<p>To access the Input manager use <code>Shaku.input</code>.</p>
</dd>
<dt><a href="#Logger">Logger</a></dt>
<dd><p>A logger manager.
By default writes logs to console.</p>
</dd>
<dt><a href="#IManager">IManager</a></dt>
<dd><p>Interface for any manager.
Manager = manages a domain in Shaku, such as gfx (graphics), sfx (sounds), input, etc.</p>
</dd>
<dt><a href="#Sfx">Sfx</a></dt>
<dd><p>Sfx manager.
Used to play sound effects and music.</p>
<p>To access the Sfx manager use <code>Shaku.sfx</code>.</p>
</dd>
<dt><a href="#SoundInstance">SoundInstance</a></dt>
<dd><p>A sound effect instance you can play and stop.</p>
</dd>
<dt><a href="#SoundMixer">SoundMixer</a></dt>
<dd><p>A utility class to mix between two sounds.</p>
</dd>
<dt><a href="#Shaku">Shaku</a></dt>
<dd><p>Shaku's main object.
This object wraps the entire lib namespace, and this is what you use to access all managers and manage your main loop.</p>
</dd>
<dt><a href="#Animator">Animator</a></dt>
<dd><p>Implement an animator object that change values over time using Linear Interpolation.
Usage example:
(new Animator(sprite)).from({'position.x': 0}).to({'position.x': 100}).duration(1).play();</p>
</dd>
<dt><a href="#Box">Box</a></dt>
<dd><p>A 3D box shape.</p>
</dd>
<dt><a href="#Circle">Circle</a></dt>
<dd><p>Implement a simple 2d Circle.</p>
</dd>
<dt><a href="#Color">Color</a></dt>
<dd><p>Implement a color.
All color components are expected to be in 0.0 - 1.0 range (and not 0-255).</p>
</dd>
<dt><a href="#Frustum">Frustum</a></dt>
<dd><p>Implement a 3D Frustum shape.</p>
</dd>
<dt><a href="#GameTime">GameTime</a></dt>
<dd><p>Class to hold current game time, both elapse and delta from last frame.</p>
</dd>
<dt><a href="#ItemsSorter">ItemsSorter</a></dt>
<dd><p>Utility class to arrange rectangles in minimal region.</p>
</dd>
<dt><a href="#Line">Line</a></dt>
<dd><p>Implement a simple 2d Line.</p>
</dd>
<dt><a href="#MathHelper">MathHelper</a></dt>
<dd><p>Implement some math utilities functions.</p>
</dd>
<dt><a href="#Matrix">Matrix</a></dt>
<dd><p>Implements a matrix.</p>
</dd>
<dt><a href="#IGrid">IGrid</a></dt>
<dd><p>Interface for a supported grid.</p>
</dd>
<dt><a href="#Node">Node</a></dt>
<dd><p>A path node.</p>
</dd>
<dt><a href="#Perlin">Perlin</a></dt>
<dd><p>Generate 2d perlin noise.
Based on code from noisejs by Stefan Gustavson.
<a href="https://github.com/josephg/noisejs/blob/master/perlin.js">https://github.com/josephg/noisejs/blob/master/perlin.js</a></p>
</dd>
<dt><a href="#Plane">Plane</a></dt>
<dd><p>A plane in 3D space.</p>
</dd>
<dt><a href="#Ray">Ray</a></dt>
<dd><p>A 3D ray.</p>
</dd>
<dt><a href="#Rectangle">Rectangle</a></dt>
<dd><p>Implement a simple 2d Rectangle.</p>
</dd>
<dt><a href="#SeededRandom">SeededRandom</a></dt>
<dd><p>Class to generate random numbers with seed.</p>
</dd>
<dt><a href="#Sphere">Sphere</a></dt>
<dd><p>A 3D sphere.</p>
</dd>
<dt><a href="#Storage">Storage</a></dt>
<dd><p>A thin wrapper layer around storage utility.</p>
</dd>
<dt><a href="#StorageAdapter">StorageAdapter</a></dt>
<dd><p>Storage adapter class that implement access to a storage device.
Used by the Storage utilitiy.</p>
</dd>
<dt><a href="#StorageAdapterMemory">StorageAdapterMemory</a></dt>
<dd><p>Implement simple memory storage adapter.</p>
</dd>
<dt><a href="#StorageAdapterLocalStorage">StorageAdapterLocalStorage</a></dt>
<dd><p>Implement simple localstorage storage adapter.</p>
</dd>
<dt><a href="#StorageAdapterSessionStorage">StorageAdapterSessionStorage</a></dt>
<dd><p>Implement simple sessionStorage storage adapter.</p>
</dd>
<dt><a href="#Transformation">Transformation</a></dt>
<dd><p>Transformations helper class to store 2d position, rotation and scale.
Can also perform transformations inheritance, where we combine local with parent transformations.</p>
</dd>
<dt><a href="#Vector2">Vector2</a></dt>
<dd><p>A simple Vector object for 2d positions.</p>
</dd>
<dt><a href="#Vector3">Vector3</a></dt>
<dd><p>A Vector object for 3d positions.</p>
</dd>
</dl>
## Typedefs
<dl>
<dt><a href="#BlendMode">BlendMode</a> : <code>String</code></dt>
<dd></dd>
<dt><a href="#BuffersUsage">BuffersUsage</a> : <code>String</code></dt>
<dd></dd>
<dt><a href="#UniformType">UniformType</a> : <code>String</code></dt>
<dd></dd>
<dt><a href="#TextAlignment">TextAlignment</a> : <code>String</code></dt>
<dd></dd>
<dt><a href="#TextureFilterMode">TextureFilterMode</a> : <code>String</code></dt>
<dd></dd>
<dt><a href="#TextureWrapMode">TextureWrapMode</a> : <code>String</code></dt>
<dd></dd>
<dt><a href="#MouseButton">MouseButton</a> : <code>Number</code></dt>
<dd></dd>
<dt><a href="#KeyboardKey">KeyboardKey</a> : <code>Number</code></dt>
<dd></dd>
</dl>
<a name="Asset"></a>
## Asset
A loadable asset base class.
All asset types inherit from this.
**Kind**: global class
* [Asset](#Asset)
* [new Asset(url)](#new_Asset_new)
* [.ready](#Asset+ready) ⇒ <code>Boolean</code>
* [.url](#Asset+url) ⇒ <code>String</code>
* [.valid](#Asset+valid) ⇒ <code>Boolean</code>
* [.onReady(callback)](#Asset+onReady)
* [.waitForReady()](#Asset+waitForReady) ⇒ <code>Promise</code>
* [.load(params)](#Asset+load) ⇒ <code>Promise</code>
* [.create(source, params)](#Asset+create) ⇒ <code>Promise</code>
* [.destroy()](#Asset+destroy)
<a name="new_Asset_new"></a>
### new Asset(url)
Create the new asset.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL / identifier. |
<a name="Asset+ready"></a>
### asset.ready ⇒ <code>Boolean</code>
Get if this asset is ready, ie loaded or created.
**Kind**: instance property of [<code>Asset</code>](#Asset)
**Returns**: <code>Boolean</code> - True if asset finished loading / creating. This doesn't mean its necessarily valid, only that its done loading.
<a name="Asset+url"></a>
### asset.url ⇒ <code>String</code>
Get asset's URL.
**Kind**: instance property of [<code>Asset</code>](#Asset)
**Returns**: <code>String</code> - Asset URL.
<a name="Asset+valid"></a>
### asset.valid ⇒ <code>Boolean</code>
Get if this asset is loaded and valid.
**Kind**: instance property of [<code>Asset</code>](#Asset)
**Returns**: <code>Boolean</code> - True if asset is loaded and valid, false otherwise.
<a name="Asset+onReady"></a>
### asset.onReady(callback)
Register a method to be called when asset is ready.
If asset is already in ready state, will invoke immediately.
**Kind**: instance method of [<code>Asset</code>](#Asset)
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | Callback to invoke when asset is ready. |
<a name="Asset+waitForReady"></a>
### asset.waitForReady() ⇒ <code>Promise</code>
Return a promise to resolve when ready.
**Kind**: instance method of [<code>Asset</code>](#Asset)
**Returns**: <code>Promise</code> - Promise to resolve when ready.
<a name="Asset+load"></a>
### asset.load(params) ⇒ <code>Promise</code>
Load the asset from it's URL.
**Kind**: instance method of [<code>Asset</code>](#Asset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
| Param | Type | Description |
| --- | --- | --- |
| params | <code>\*</code> | Optional additional params. |
<a name="Asset+create"></a>
### asset.create(source, params) ⇒ <code>Promise</code>
Create the asset from data source.
**Kind**: instance method of [<code>Asset</code>](#Asset)
**Returns**: <code>Promise</code> - Promise to resolve when asset is ready.
| Param | Type | Description |
| --- | --- | --- |
| source | <code>\*</code> | Data to create asset from. |
| params | <code>\*</code> | Optional additional params. |
<a name="Asset+destroy"></a>
### asset.destroy()
Destroy the asset, freeing any allocated resources in the process.
**Kind**: instance method of [<code>Asset</code>](#Asset)
<a name="Assets"></a>
## Assets
Assets manager class.
Used to create, load and cache game assets, which includes textures, audio files, JSON objects, etc.
As a rule of thumb, all methods to load or create assets are async and return a promise.
To access the Assets manager you use `Shaku.assets`.
**Kind**: global class
* [Assets](#Assets)
* [new Assets()](#new_Assets_new)
* [.root](#Assets+root)
* [.suffix](#Assets+suffix)
* [.pendingAssets](#Assets+pendingAssets) ⇒ <code>Array.<string></code>
* [.failedAssets](#Assets+failedAssets) ⇒ <code>Array.<string></code>
* [.waitForAll()](#Assets+waitForAll) ⇒ <code>Promise</code>
* [.getCached(url)](#Assets+getCached) ⇒ [<code>Asset</code>](#Asset)
* [.loadSound(url)](#Assets+loadSound) ⇒ [<code>Promise.<SoundAsset></code>](#SoundAsset)
* [.loadTexture(url, [params])](#Assets+loadTexture) ⇒ [<code>Promise.<TextureAsset></code>](#TextureAsset)
* [.createRenderTarget(name, width, height, [channels])](#Assets+createRenderTarget) ⇒ [<code>Promise.<TextureAsset></code>](#TextureAsset)
* [.createTextureAtlas(name, sources, [maxWidth], [maxHeight], [extraMargins])](#Assets+createTextureAtlas) ⇒ <code>Promise.<TextureAtlas></code>
* [.loadFontTexture(url, params)](#Assets+loadFontTexture) ⇒ [<code>Promise.<FontTextureAsset></code>](#FontTextureAsset)
* [.loadMsdfFontTexture(url, [params])](#Assets+loadMsdfFontTexture) ⇒ [<code>Promise.<MsdfFontTextureAsset></code>](#MsdfFontTextureAsset)
* [.loadJson(url)](#Assets+loadJson) ⇒ [<code>Promise.<JsonAsset></code>](#JsonAsset)
* [.createJson(name, data)](#Assets+createJson) ⇒ [<code>Promise.<JsonAsset></code>](#JsonAsset)
* [.loadBinary(url)](#Assets+loadBinary) ⇒ [<code>Promise.<BinaryAsset></code>](#BinaryAsset)
* [.createBinary(name, data)](#Assets+createBinary) ⇒ [<code>Promise.<BinaryAsset></code>](#BinaryAsset)
* [.free(url)](#Assets+free)
* [.clearCache()](#Assets+clearCache)
<a name="new_Assets_new"></a>
### new Assets()
Create the manager.
<a name="Assets+root"></a>
### assets.root
Optional URL root to prepend to all loaded assets URLs.
For example, if all your assets are under '/static/assets/', you can set this url as root and omit it when loading assets later.
**Kind**: instance property of [<code>Assets</code>](#Assets)
<a name="Assets+suffix"></a>
### assets.suffix
Optional suffix to add to all loaded assets URLs.
You can use this for anti-cache mechanism if you want to reload all assets. For example, you can set this value to "'?dt=' + Date.now()".
**Kind**: instance property of [<code>Assets</code>](#Assets)
<a name="Assets+pendingAssets"></a>
### assets.pendingAssets ⇒ <code>Array.<string></code>
Get list of assets waiting to be loaded.
This list will be reset if you call clearCache().
**Kind**: instance property of [<code>Assets</code>](#Assets)
**Returns**: <code>Array.<string></code> - URLs of assets waiting to be loaded.
<a name="Assets+failedAssets"></a>
### assets.failedAssets ⇒ <code>Array.<string></code>
Get list of assets that failed to load.
This list will be reset if you call clearCache().
**Kind**: instance property of [<code>Assets</code>](#Assets)
**Returns**: <code>Array.<string></code> - URLs of assets that had error loading.
<a name="Assets+waitForAll"></a>
### assets.waitForAll() ⇒ <code>Promise</code>
Return a promise that will be resolved only when all pending assets are loaded.
If an asset fails, will reject.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: <code>Promise</code> - Promise to resolve when all assets are loaded, or reject if there are failed assets.
**Example**
```js
await Shaku.assets.waitForAll();
console.log("All assets are loaded!");
```
<a name="Assets+getCached"></a>
### assets.getCached(url) ⇒ [<code>Asset</code>](#Asset)
Get asset directly from cache, synchronous and without a Promise.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Asset</code>](#Asset) - Asset or null if not loaded.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL or name. |
<a name="Assets+loadSound"></a>
### assets.loadSound(url) ⇒ [<code>Promise.<SoundAsset></code>](#SoundAsset)
Load a sound asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<SoundAsset></code>](#SoundAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL. |
**Example**
```js
let sound = await Shaku.assets.loadSound("assets/my_sound.ogg");
```
<a name="Assets+loadTexture"></a>
### assets.loadTexture(url, [params]) ⇒ [<code>Promise.<TextureAsset></code>](#TextureAsset)
Load a texture asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<TextureAsset></code>](#TextureAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL. |
| [params] | <code>\*</code> | Optional params dictionary. See TextureAsset.load() for more details. |
**Example**
```js
let texture = await Shaku.assets.loadTexture("assets/my_texture.png", {generateMipMaps: false});
```
<a name="Assets+createRenderTarget"></a>
### assets.createRenderTarget(name, width, height, [channels]) ⇒ [<code>Promise.<TextureAsset></code>](#TextureAsset)
Create a render target texture asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<TextureAsset></code>](#TextureAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> \| <code>null</code> | Asset name (matched to URLs when using cache). If null, will not add to cache. |
| width | <code>Number</code> | Texture width. |
| height | <code>Number</code> | Texture height. |
| [channels] | <code>Number</code> | Texture channels count. Defaults to 4 (RGBA). |
**Example**
```js
let width = 512;
let height = 512;
let renderTarget = await Shaku.assets.createRenderTarget("optional_render_target_asset_id", width, height);
```
<a name="Assets+createTextureAtlas"></a>
### assets.createTextureAtlas(name, sources, [maxWidth], [maxHeight], [extraMargins]) ⇒ <code>Promise.<TextureAtlas></code>
Create a texture atlas asset.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: <code>Promise.<TextureAtlas></code> - Promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> \| <code>null</code> | Asset name (matched to URLs when using cache). If null, will not add to cache. |
| sources | <code>Array.<String></code> | List of URLs to load textures from. |
| [maxWidth] | <code>Number</code> | Optional atlas textures max width. |
| [maxHeight] | <code>Number</code> | Optional atlas textures max height. |
| [extraMargins] | [<code>Vector2</code>](#Vector2) | Optional extra empty pixels to add between textures in atlas. |
<a name="Assets+loadFontTexture"></a>
### assets.loadFontTexture(url, params) ⇒ [<code>Promise.<FontTextureAsset></code>](#FontTextureAsset)
Load a font texture asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<FontTextureAsset></code>](#FontTextureAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL. |
| params | <code>\*</code> | Optional params dictionary. See FontTextureAsset.load() for more details. |
**Example**
```js
let fontTexture = await Shaku.assets.loadFontTexture('assets/DejaVuSansMono.ttf', {fontName: 'DejaVuSansMono'});
```
<a name="Assets+loadMsdfFontTexture"></a>
### assets.loadMsdfFontTexture(url, [params]) ⇒ [<code>Promise.<MsdfFontTextureAsset></code>](#MsdfFontTextureAsset)
Load a MSDF font texture asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<MsdfFontTextureAsset></code>](#MsdfFontTextureAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL. |
| [params] | <code>\*</code> | Optional params dictionary. See MsdfFontTextureAsset.load() for more details. |
**Example**
```js
let fontTexture = await Shaku.assets.loadMsdfFontTexture('DejaVuSansMono.font', {jsonUrl: 'assets/DejaVuSansMono.json', textureUrl: 'assets/DejaVuSansMono.png'});
```
<a name="Assets+loadJson"></a>
### assets.loadJson(url) ⇒ [<code>Promise.<JsonAsset></code>](#JsonAsset)
Load a json asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<JsonAsset></code>](#JsonAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL. |
**Example**
```js
let jsonData = await Shaku.assets.loadJson('assets/my_json_data.json');
console.log(jsonData.data);
```
<a name="Assets+createJson"></a>
### assets.createJson(name, data) ⇒ [<code>Promise.<JsonAsset></code>](#JsonAsset)
Create a new json asset. If already exist, will reject promise.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<JsonAsset></code>](#JsonAsset) - promise to resolve with asset instance, when ready. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | Asset name (matched to URLs when using cache). If null, will not add to cache. |
| data | <code>Object</code> \| <code>String</code> | Optional starting data. |
**Example**
```js
let jsonData = await Shaku.assets.createJson('optional_json_data_id', {"foo": "bar"});
// you can now load this asset from anywhere in your code using 'optional_json_data_id' as url
```
<a name="Assets+loadBinary"></a>
### assets.loadBinary(url) ⇒ [<code>Promise.<BinaryAsset></code>](#BinaryAsset)
Load a binary data asset. If already loaded, will use cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<BinaryAsset></code>](#BinaryAsset) - promise to resolve with asset instance, when loaded. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL. |
**Example**
```js
let binData = await Shaku.assets.loadBinary('assets/my_bin_data.dat');
console.log(binData.data);
```
<a name="Assets+createBinary"></a>
### assets.createBinary(name, data) ⇒ [<code>Promise.<BinaryAsset></code>](#BinaryAsset)
Create a new binary asset. If already exist, will reject promise.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Returns**: [<code>Promise.<BinaryAsset></code>](#BinaryAsset) - promise to resolve with asset instance, when ready. You can access the loading asset with `.asset` on the promise.
| Param | Type | Description |
| --- | --- | --- |
| name | <code>String</code> | Asset name (matched to URLs when using cache). If null, will not add to cache. |
| data | <code>Array.<Number></code> \| <code>Uint8Array</code> | Binary data to set. |
**Example**
```js
let binData = await Shaku.assets.createBinary('optional_bin_data_id', [1,2,3,4]);
// you can now load this asset from anywhere in your code using 'optional_bin_data_id' as url
```
<a name="Assets+free"></a>
### assets.free(url)
Destroy and free asset from cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
| Param | Type | Description |
| --- | --- | --- |
| url | <code>String</code> | Asset URL to free. |
**Example**
```js
Shaku.assets.free("my_asset_url");
```
<a name="Assets+clearCache"></a>
### assets.clearCache()
Free all loaded assets from cache.
**Kind**: instance method of [<code>Assets</code>](#Assets)
**Example**
```js
Shaku.assets.clearCache();
```
<a name="BinaryAsset"></a>
## BinaryAsset
A loadable binary data asset.
This asset type loads array of bytes from a remote file.
**Kind**: global class
* [BinaryAsset](#BinaryAsset)
* [.valid](#BinaryAsset+valid)
* [.data](#BinaryAsset+data) ⇒ <code>Uint8Array</code>
* [.load()](#BinaryAsset+load) ⇒ <code>Promise</code>
* [.create(source)](#BinaryAsset+create) ⇒ <code>Promise</code>
* [.destroy()](#BinaryAsset+destroy)
* [.string()](#BinaryAsset+string) ⇒ <code>String</code>
<a name="BinaryAsset+valid"></a>
### binaryAsset.valid
**Kind**: instance property of [<code>BinaryAsset</code>](#BinaryAsset)
<a name="BinaryAsset+data"></a>
### binaryAsset.data ⇒ <code>Uint8Array</code>
Get binary data.
**Kind**: instance property of [<code>BinaryAsset</code>](#BinaryAsset)
**Returns**: <code>Uint8Array</code> - Data as bytes array.
<a name="BinaryAsset+load"></a>
### binaryAsset.load() ⇒ <code>Promise</code>
Load the binary data from the asset URL.
**Kind**: instance method of [<code>BinaryAsset</code>](#BinaryAsset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
<a name="BinaryAsset+create"></a>
### binaryAsset.create(source) ⇒ <code>Promise</code>
Create the binary data asset from array or Uint8Array.
**Kind**: instance method of [<code>BinaryAsset</code>](#BinaryAsset)
**Returns**: <code>Promise</code> - Promise to resolve when asset is ready.
| Param | Type | Description |
| --- | --- | --- |
| source | <code>Array.<Number></code> \| <code>Uint8Array</code> | Data to create asset from. |
<a name="BinaryAsset+destroy"></a>
### binaryAsset.destroy()
**Kind**: instance method of [<code>BinaryAsset</code>](#BinaryAsset)
<a name="BinaryAsset+string"></a>
### binaryAsset.string() ⇒ <code>String</code>
Convert and return data as string.
**Kind**: instance method of [<code>BinaryAsset</code>](#BinaryAsset)
**Returns**: <code>String</code> - Data converted to string.
<a name="FontTextureAsset"></a>
## FontTextureAsset
A font texture asset, dynamically generated from loaded font and canvas.
This asset type creates an atlas of all the font's characters as textures, so we can later render them as sprites.
**Kind**: global class
* [FontTextureAsset](#FontTextureAsset)
* [.lineHeight](#FontTextureAsset+lineHeight)
* [.fontName](#FontTextureAsset+fontName)
* [.fontSize](#FontTextureAsset+fontSize)
* [.placeholderCharacter](#FontTextureAsset+placeholderCharacter)
* [.texture](#FontTextureAsset+texture)
* [.width](#FontTextureAsset+width) ⇒ <code>Number</code>
* [.height](#FontTextureAsset+height) ⇒ <code>Number</code>
* [.valid](#FontTextureAsset+valid)
* [.load(params)](#FontTextureAsset+load) ⇒ <code>Promise</code>
* [.getSize()](#FontTextureAsset+getSize) ⇒ [<code>Vector2</code>](#Vector2)
* [.getSourceRect(character)](#FontTextureAsset+getSourceRect) ⇒ [<code>Rectangle</code>](#Rectangle)
* [.getPositionOffset(character)](#FontTextureAsset+getPositionOffset) ⇒ [<code>Vector2</code>](#Vector2)
* [.getXAdvance(character)](#FontTextureAsset+getXAdvance) ⇒ <code>Number</code>
* [.destroy()](#FontTextureAsset+destroy)
<a name="FontTextureAsset+lineHeight"></a>
### fontTextureAsset.lineHeight
Get line height.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="FontTextureAsset+fontName"></a>
### fontTextureAsset.fontName
Get font name.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="FontTextureAsset+fontSize"></a>
### fontTextureAsset.fontSize
Get font size.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="FontTextureAsset+placeholderCharacter"></a>
### fontTextureAsset.placeholderCharacter
Get placeholder character.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="FontTextureAsset+texture"></a>
### fontTextureAsset.texture
Get the texture.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="FontTextureAsset+width"></a>
### fontTextureAsset.width ⇒ <code>Number</code>
Get texture width.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: <code>Number</code> - Texture width.
<a name="FontTextureAsset+height"></a>
### fontTextureAsset.height ⇒ <code>Number</code>
Get texture height.
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: <code>Number</code> - Texture height.
<a name="FontTextureAsset+valid"></a>
### fontTextureAsset.valid
**Kind**: instance property of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="FontTextureAsset+load"></a>
### fontTextureAsset.load(params) ⇒ <code>Promise</code>
Generate the font texture from a font found in given URL.
**Kind**: instance method of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
| Param | Type | Description |
| --- | --- | --- |
| params | <code>\*</code> | Additional params. Possible values are: - fontName: mandatory font name. on some browsers if the font name does not match the font you actually load via the URL, it will not be loaded properly. - missingCharPlaceholder (default='?'): character to use for missing characters. - smoothFont (default=true): if true, will set font to smooth mode. - fontSize (default=52): font size in texture. larget font size will take more memory, but allow for sharper text rendering in larger scales. - enforceTexturePowerOfTwo (default=true): if true, will force texture size to be power of two. - maxTextureWidth (default=1024): max texture width. - charactersSet (default=FontTextureAsset.defaultCharactersSet): which characters to set in the texture. - extraPadding (default=0,0): Optional extra padding to add around characters in texture. - sourceRectOffsetAdjustment (default=0,0): Optional extra offset in characters source rectangles. Use this for fonts that are too low / height and bleed into other characters source rectangles. |
<a name="FontTextureAsset+getSize"></a>
### fontTextureAsset.getSize() ⇒ [<code>Vector2</code>](#Vector2)
Get texture size as a vector.
**Kind**: instance method of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: [<code>Vector2</code>](#Vector2) - Texture size.
<a name="FontTextureAsset+getSourceRect"></a>
### fontTextureAsset.getSourceRect(character) ⇒ [<code>Rectangle</code>](#Rectangle)
Get the source rectangle for a given character in texture.
**Kind**: instance method of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: [<code>Rectangle</code>](#Rectangle) - Source rectangle for character.
| Param | Type | Description |
| --- | --- | --- |
| character | <code>Character</code> | Character to get source rect for. |
<a name="FontTextureAsset+getPositionOffset"></a>
### fontTextureAsset.getPositionOffset(character) ⇒ [<code>Vector2</code>](#Vector2)
When drawing the character, get the offset to add to the cursor.
**Kind**: instance method of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: [<code>Vector2</code>](#Vector2) - Offset to add to the cursor before drawing the character.
| Param | Type | Description |
| --- | --- | --- |
| character | <code>Character</code> | Character to get the offset for. |
<a name="FontTextureAsset+getXAdvance"></a>
### fontTextureAsset.getXAdvance(character) ⇒ <code>Number</code>
Get how much to advance the cursor when drawing this character.
**Kind**: instance method of [<code>FontTextureAsset</code>](#FontTextureAsset)
**Returns**: <code>Number</code> - Distance to move the cursor after drawing the character.
| Param | Type | Description |
| --- | --- | --- |
| character | <code>Character</code> | Character to get the advance for. |
<a name="FontTextureAsset+destroy"></a>
### fontTextureAsset.destroy()
**Kind**: instance method of [<code>FontTextureAsset</code>](#FontTextureAsset)
<a name="JsonAsset"></a>
## JsonAsset
A loadable json asset.
This asset type loads JSON from a remote file.
**Kind**: global class
* [JsonAsset](#JsonAsset)
* [.data](#JsonAsset+data) ⇒ <code>\*</code>
* [.valid](#JsonAsset+valid)
* [.load()](#JsonAsset+load) ⇒ <code>Promise</code>
* [.create(source)](#JsonAsset+create) ⇒ <code>Promise</code>
* [.destroy()](#JsonAsset+destroy)
<a name="JsonAsset+data"></a>
### jsonAsset.data ⇒ <code>\*</code>
Get json data.
**Kind**: instance property of [<code>JsonAsset</code>](#JsonAsset)
**Returns**: <code>\*</code> - Data as dictionary.
<a name="JsonAsset+valid"></a>
### jsonAsset.valid
**Kind**: instance property of [<code>JsonAsset</code>](#JsonAsset)
<a name="JsonAsset+load"></a>
### jsonAsset.load() ⇒ <code>Promise</code>
Load the JSON data from the asset URL.
**Kind**: instance method of [<code>JsonAsset</code>](#JsonAsset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
<a name="JsonAsset+create"></a>
### jsonAsset.create(source) ⇒ <code>Promise</code>
Create the JSON data asset from object or string.
**Kind**: instance method of [<code>JsonAsset</code>](#JsonAsset)
**Returns**: <code>Promise</code> - Promise to resolve when asset is ready.
| Param | Type | Description |
| --- | --- | --- |
| source | <code>Object</code> \| <code>String</code> | Data to create asset from. |
<a name="JsonAsset+destroy"></a>
### jsonAsset.destroy()
**Kind**: instance method of [<code>JsonAsset</code>](#JsonAsset)
<a name="MsdfFontTextureAsset"></a>
## MsdfFontTextureAsset
A MSDF font texture asset, from a pregenerated msdf texture atlas (from msdf-bmfont-xml, for example).
This asset uses a signed distance field atlas to render characters as sprites at high res.
**Kind**: global class
* [MsdfFontTextureAsset](#MsdfFontTextureAsset)
* [.width](#MsdfFontTextureAsset+width) ⇒ <code>Number</code>
* [.height](#MsdfFontTextureAsset+height) ⇒ <code>Number</code>
* [.load(params)](#MsdfFontTextureAsset+load) ⇒ <code>Promise</code>
* [.getSize()](#MsdfFontTextureAsset+getSize) ⇒ [<code>Vector2</code>](#Vector2)
* [.getPositionOffset()](#MsdfFontTextureAsset+getPositionOffset)
* [.getXAdvance()](#MsdfFontTextureAsset+getXAdvance)
* [.destroy()](#MsdfFontTextureAsset+destroy)
<a name="MsdfFontTextureAsset+width"></a>
### msdfFontTextureAsset.width ⇒ <code>Number</code>
Get texture width.
**Kind**: instance property of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
**Returns**: <code>Number</code> - Texture width.
<a name="MsdfFontTextureAsset+height"></a>
### msdfFontTextureAsset.height ⇒ <code>Number</code>
Get texture height.
**Kind**: instance property of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
**Returns**: <code>Number</code> - Texture height.
<a name="MsdfFontTextureAsset+load"></a>
### msdfFontTextureAsset.load(params) ⇒ <code>Promise</code>
Generate the font metadata and texture from the given URL.
**Kind**: instance method of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
| Param | Type | Description |
| --- | --- | --- |
| params | <code>\*</code> | Additional params. Possible values are: - jsonUrl: mandatory url for the font's json metadata (generated via msdf-bmfont-xml, for example) - textureUrl: mandatory url for the font's texture atlas (generated via msdf-bmfont-xml, for example) - missingCharPlaceholder (default='?'): character to use for missing characters. |
<a name="MsdfFontTextureAsset+getSize"></a>
### msdfFontTextureAsset.getSize() ⇒ [<code>Vector2</code>](#Vector2)
Get texture size as a vector.
**Kind**: instance method of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
**Returns**: [<code>Vector2</code>](#Vector2) - Texture size.
<a name="MsdfFontTextureAsset+getPositionOffset"></a>
### msdfFontTextureAsset.getPositionOffset()
**Kind**: instance method of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
<a name="MsdfFontTextureAsset+getXAdvance"></a>
### msdfFontTextureAsset.getXAdvance()
**Kind**: instance method of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
<a name="MsdfFontTextureAsset+destroy"></a>
### msdfFontTextureAsset.destroy()
**Kind**: instance method of [<code>MsdfFontTextureAsset</code>](#MsdfFontTextureAsset)
<a name="SoundAsset"></a>
## SoundAsset
A loadable sound asset.
This is the asset type you use to play sounds.
**Kind**: global class
* [SoundAsset](#SoundAsset)
* [.valid](#SoundAsset+valid)
* [.load()](#SoundAsset+load) ⇒ <code>Promise</code>
* [.destroy()](#SoundAsset+destroy)
<a name="SoundAsset+valid"></a>
### soundAsset.valid
**Kind**: instance property of [<code>SoundAsset</code>](#SoundAsset)
<a name="SoundAsset+load"></a>
### soundAsset.load() ⇒ <code>Promise</code>
Load the sound asset from its URL.
Note that loading sounds isn't actually necessary to play sounds, this method merely pre-load the asset (so first time we play
the sound would be immediate and not delayed) and validate the data is valid.
**Kind**: instance method of [<code>SoundAsset</code>](#SoundAsset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
<a name="SoundAsset+destroy"></a>
### soundAsset.destroy()
**Kind**: instance method of [<code>SoundAsset</code>](#SoundAsset)
<a name="TextureAsset"></a>
## TextureAsset
A loadable texture asset.
This asset type loads an image from URL or source, and turn it into a texture.
**Kind**: global class
* [TextureAsset](#TextureAsset)
* [.image](#TextureAsset+image)
* [.width](#TextureAsset+width)
* [.height](#TextureAsset+height)
* [._glTexture](#TextureAsset+_glTexture)
* [.valid](#TextureAsset+valid)
* [.load(params)](#TextureAsset+load) ⇒ <code>Promise</code>
* [.createRenderTarget(width, height, channels)](#TextureAsset+createRenderTarget)
* [.fromImage(image, params)](#TextureAsset+fromImage)
* [.create(source, params)](#TextureAsset+create) ⇒ <code>Promise</code>
* [.getPixel(x, y)](#TextureAsset+getPixel) ⇒ [<code>Color</code>](#Color)
* [.getPixelsData([x], [y], [width], [height])](#TextureAsset+getPixelsData) ⇒ <code>Array.<Array.<Color>></code>
* [.destroy()](#TextureAsset+destroy)
<a name="TextureAsset+image"></a>
### textureAsset.image
**Kind**: instance property of [<code>TextureAsset</code>](#TextureAsset)
<a name="TextureAsset+width"></a>
### textureAsset.width
**Kind**: instance property of [<code>TextureAsset</code>](#TextureAsset)
<a name="TextureAsset+height"></a>
### textureAsset.height
**Kind**: instance property of [<code>TextureAsset</code>](#TextureAsset)
<a name="TextureAsset+_glTexture"></a>
### textureAsset.\_glTexture
**Kind**: instance property of [<code>TextureAsset</code>](#TextureAsset)
<a name="TextureAsset+valid"></a>
### textureAsset.valid
**Kind**: instance property of [<code>TextureAsset</code>](#TextureAsset)
<a name="TextureAsset+load"></a>
### textureAsset.load(params) ⇒ <code>Promise</code>
Load the texture from it's image URL.
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
**Returns**: <code>Promise</code> - Promise to resolve when fully loaded.
| Param | Type | Description |
| --- | --- | --- |
| params | <code>\*</code> | Optional additional params. Possible values are: - generateMipMaps (default=false): if true, will generate mipmaps for this texture. - crossOrigin (default=undefined): if set, will set the crossOrigin property with this value. - flipY (default=false): if true, will flip texture on Y axis. - premultiplyAlpha (default=false): if true, will load texture with premultiply alpha flag set. |
<a name="TextureAsset+createRenderTarget"></a>
### textureAsset.createRenderTarget(width, height, channels)
Create this texture as an empty render target.
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
| Param | Type | Description |
| --- | --- | --- |
| width | <code>Number</code> | Texture width. |
| height | <code>Number</code> | Texture height. |
| channels | <code>Number</code> | Texture channels count. Defaults to 4 (RGBA). |
<a name="TextureAsset+fromImage"></a>
### textureAsset.fromImage(image, params)
Create texture from loaded image instance.
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
**See**: TextureAsset.load for params.
| Param | Type | Description |
| --- | --- | --- |
| image | <code>Image</code> | Image to create texture from. Image must be loaded! |
| params | <code>\*</code> | Optional additional params. See load() for details. |
<a name="TextureAsset+create"></a>
### textureAsset.create(source, params) ⇒ <code>Promise</code>
Create the texture from an image.
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
**Returns**: <code>Promise</code> - Promise to resolve when asset is ready.
**See**: TextureAsset.load for params.
| Param | Type | Description |
| --- | --- | --- |
| source | <code>Image</code> \| <code>String</code> | Image or Image source URL to create texture from. |
| params | <code>\*</code> | Optional additional params. See load() for details. |
<a name="TextureAsset+getPixel"></a>
### textureAsset.getPixel(x, y) ⇒ [<code>Color</code>](#Color)
Get pixel color from image.
Note: this method is quite slow, if you need to perform multiple queries consider using `getPixelsData()` once to get all pixels data instead.
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
**Returns**: [<code>Color</code>](#Color) - Pixel color.
| Param | Type | Description |
| --- | --- | --- |
| x | <code>Number</code> | Pixel X value. |
| y | <code>Number</code> | Pixel Y value. |
<a name="TextureAsset+getPixelsData"></a>
### textureAsset.getPixelsData([x], [y], [width], [height]) ⇒ <code>Array.<Array.<Color>></code>
Get a 2D array with pixel colors.
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
**Returns**: <code>Array.<Array.<Color>></code> - A 2D array with all texture pixel colors.
| Param | Type | Description |
| --- | --- | --- |
| [x] | <code>Number</code> | Offset X in texture to get. Defaults to 0. |
| [y] | <code>Number</code> | Offset Y in texture to get. Defaults to 0. |
| [width] | <code>Number</code> | How many pixels to get on X axis. Defaults to texture width - x. |
| [height] | <code>Number</code> | How many pixels to get on Y axis. Defaults to texture height - y. |
<a name="TextureAsset+destroy"></a>
### textureAsset.destroy()
**Kind**: instance method of [<code>TextureAsset</code>](#TextureAsset)
<a name="TextureAssetBase"></a>
## TextureAssetBase
Base type for all texture asset types.
**Kind**: global class
* [TextureAssetBase](#TextureAssetBase)
* [.filter](#TextureAssetBase+filter)
* [.filter](#TextureAssetBase+filter)
* [.wrapMode](#TextureAssetBase+wrapMode)
* [.wrapMode](#TextureAssetBase+wrapMode)
* [.image](#TextureAssetBase+image) ⇒ <code>Image</code>
* [.width](#TextureAssetBase+width) ⇒ <code>Number</code>
* [.height](#TextureAssetBase+height) ⇒ <code>Number</code>
* [._glTexture](#TextureAssetBase+_glTexture)
* [.getSize()](#TextureAssetBase+getSize) ⇒ [<code>Vector2</code>](#Vector2)
<a name="TextureAssetBase+filter"></a>
### textureAssetBase.filter
Get texture magnifying filter, or null to use default.
**Kind**: instance property of [<code>TextureAssetBase</code>](#TextureAssetBase)
**See**: Shaku.gfx.TextureFilterModes
<a name="TextureAssetBase+filter"></a>
### textureAssetBase.filter
Set texture magnifying filter.
**Kind**: instance property of [<code>TextureAssetBase</code>](#TextureAssetBase)
**See**: Shaku.gfx.TextureFilterModes
| Param | Type | Description |
| --- | --- | --- |
| value | [<code>TextureFilterMode</code>](#TextureFilterMode) | Filter mode to use or null to use default. |
<a name="TextureAssetBase+wrapMode"></a>
### textureAssetBase.wrapMode
Get texture wrapping mode, or null to use default.
**Kind**: instance property of [<code>TextureAssetBase</code>](#TextureAssetBase)
**See**: Shaku.gfx.TextureWrapM