
A loadable asset base class. All asset types inherit from this.
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.
A loadable binary data asset. This asset type loads array of bytes from a remote file.
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.
A loadable json asset. This asset type loads JSON from a remote file.
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.
A loadable sound asset. This is the asset type you use to play sounds.
A loadable texture asset. This asset type loads an image from URL or source, and turn it into a texture.
Base type for all texture asset types.
A texture atlas we can build at runtime to combine together multiple textures.
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.
Collision is the collision manager. It provides basic 2d collision detection functionality. Note: this is not a physics engine, its only for detection and objects picking.
To access the Collision manager you use Shaku.collision.
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.
The collision resolver is responsible to implement collision detection between pair of shapes of same or different types.
Collision detection result.
Collision circle class.
Collision lines class. This shape is made of one line or more.
Collision point class.
Collision rectangle class.
Collision shape base class.
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.
Implements a Camera object.
Implements a 3d Camera object.
Base class for a drawing batch, used to draw a collection of sprites or shapes.
Colored lines renderer. Responsible to drawing a batch of line segments or strips.
Colored shapes renderer. Responsible to drawing a batch of basic geometric shapes with as little draw calls as possible.
Sprite batch renderer. Responsible to drawing a batch of sprites with as little draw calls as possible.
3D Sprites batch renderer. Responsible to drawing 3D quads with textures on them.
Base class for sprite-based rendering, ie vertices with textures.
Text sprite batch renderer. Responsible to drawing a batch of characters sprites.
Effect base class. An effect = vertex shader + fragment shader + uniforms & attributes + setup code.
Default effect to draw MSDF font textures.
Default basic effect to draw 2d shapes.
Default basic effect to draw 2d sprites.
Default basic effect to draw 2d sprites.
Default basic effect to draw 2d sprites without vertex color.
Default basic effect to draw 2d sprites with outline.
Gfx is the graphics manager. Everything related to rendering and managing your game canvas goes here.
To access the Graphics manager you use Shaku.gfx.
Sprite class.
Sprites group class. This object is a container to hold sprites collection + parent transformations. You need SpritesGroup to use batched rendering.
A vertex we can push to sprite batch.
Gamepad data object. This object represents a snapshot of a gamepad state, it does not update automatically.
Buttons cluster container - 4 buttons.
Buttons cluster container - 3 buttons.
Front buttons.
Input manager. Used to recieve input from keyboard and mouse.
To access the Input manager use Shaku.input.
A logger manager. By default writes logs to console.
Interface for any manager. Manager = manages a domain in Shaku, such as gfx (graphics), sfx (sounds), input, etc.
Sfx manager. Used to play sound effects and music.
To access the Sfx manager use Shaku.sfx.
A sound effect instance you can play and stop.
A utility class to mix between two sounds.
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.
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();
A 3D box shape.
Implement a simple 2d Circle.
Implement a color. All color components are expected to be in 0.0 - 1.0 range (and not 0-255).
Implement a 3D Frustum shape.
Class to hold current game time, both elapse and delta from last frame.
Utility class to arrange rectangles in minimal region.
Implement a simple 2d Line.
Implement some math utilities functions.
Implements a matrix.
Interface for a supported grid.
A path node.
Generate 2d perlin noise. Based on code from noisejs by Stefan Gustavson. https://github.com/josephg/noisejs/blob/master/perlin.js
A plane in 3D space.
A 3D ray.
Implement a simple 2d Rectangle.
Class to generate random numbers with seed.
A 3D sphere.
A thin wrapper layer around storage utility.
Storage adapter class that implement access to a storage device. Used by the Storage utilitiy.
Implement simple memory storage adapter.
Implement simple localstorage storage adapter.
Implement simple sessionStorage storage adapter.
Transformations helper class to store 2d position, rotation and scale. Can also perform transformations inheritance, where we combine local with parent transformations.
A simple Vector object for 2d positions.
A Vector object for 3d positions.
StringStringStringStringStringStringNumberNumberA loadable asset base class. All asset types inherit from this.
Kind: global class
BooleanStringBooleanPromisePromisePromiseCreate the new asset.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL / identifier. |
BooleanGet if this asset is ready, ie loaded or created.
Kind: instance property of Asset
Returns: Boolean - True if asset finished loading / creating. This doesn’t mean its necessarily valid, only that its done loading.
StringGet asset’s URL.
Kind: instance property of Asset
Returns: String - Asset URL.
BooleanGet if this asset is loaded and valid.
Kind: instance property of Asset
Returns: Boolean - True if asset is loaded and valid, false otherwise.
Register a method to be called when asset is ready. If asset is already in ready state, will invoke immediately.
Kind: instance method of Asset
| Param | Type | Description |
|---|---|---|
| callback | function |
Callback to invoke when asset is ready. |
PromiseReturn a promise to resolve when ready.
Kind: instance method of Asset
Returns: Promise - Promise to resolve when ready.
PromiseLoad the asset from it’s URL.
Kind: instance method of Asset
Returns: Promise - Promise to resolve when fully loaded.
| Param | Type | Description |
|---|---|---|
| params | \* |
Optional additional params. |
PromiseCreate the asset from data source.
Kind: instance method of Asset
Returns: Promise - Promise to resolve when asset is ready.
| Param | Type | Description |
|---|---|---|
| source | \* |
Data to create asset from. |
| params | \* |
Optional additional params. |
Destroy the asset, freeing any allocated resources in the process.
Kind: instance method of Asset
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
Array.<string>Array.<string>PromiseAssetPromise.<SoundAsset>Promise.<TextureAsset>Promise.<TextureAsset>Promise.<TextureAtlas>Promise.<FontTextureAsset>Promise.<MsdfFontTextureAsset>Promise.<JsonAsset>Promise.<JsonAsset>Promise.<BinaryAsset>Promise.<BinaryAsset>Create the manager.
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 Assets
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 Assets
Array.<string>Get list of assets waiting to be loaded. This list will be reset if you call clearCache().
Kind: instance property of Assets
Returns: Array.<string> - URLs of assets waiting to be loaded.
Array.<string>Get list of assets that failed to load. This list will be reset if you call clearCache().
Kind: instance property of Assets
Returns: Array.<string> - URLs of assets that had error loading.
PromiseReturn a promise that will be resolved only when all pending assets are loaded. If an asset fails, will reject.
Kind: instance method of Assets
Returns: Promise - Promise to resolve when all assets are loaded, or reject if there are failed assets.
Example
await Shaku.assets.waitForAll();
console.log("All assets are loaded!");
AssetGet asset directly from cache, synchronous and without a Promise.
Kind: instance method of Assets
Returns: Asset - Asset or null if not loaded.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL or name. |
Promise.<SoundAsset>Load a sound asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<SoundAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL. |
Example
let sound = await Shaku.assets.loadSound("assets/my_sound.ogg");
Promise.<TextureAsset>Load a texture asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<TextureAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL. |
| [params] | \* |
Optional params dictionary. See TextureAsset.load() for more details. |
Example
let texture = await Shaku.assets.loadTexture("assets/my_texture.png", {generateMipMaps: false});
Promise.<TextureAsset>Create a render target texture asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<TextureAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| name | String | null |
Asset name (matched to URLs when using cache). If null, will not add to cache. |
| width | Number |
Texture width. |
| height | Number |
Texture height. |
| [channels] | Number |
Texture channels count. Defaults to 4 (RGBA). |
Example
let width = 512;
let height = 512;
let renderTarget = await Shaku.assets.createRenderTarget("optional_render_target_asset_id", width, height);
Promise.<TextureAtlas>Create a texture atlas asset.
Kind: instance method of Assets
Returns: Promise.<TextureAtlas> - Promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| name | String | null |
Asset name (matched to URLs when using cache). If null, will not add to cache. |
| sources | Array.<String> |
List of URLs to load textures from. |
| [maxWidth] | Number |
Optional atlas textures max width. |
| [maxHeight] | Number |
Optional atlas textures max height. |
| [extraMargins] | Vector2 |
Optional extra empty pixels to add between textures in atlas. |
Promise.<FontTextureAsset>Load a font texture asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<FontTextureAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL. |
| params | \* |
Optional params dictionary. See FontTextureAsset.load() for more details. |
Example
let fontTexture = await Shaku.assets.loadFontTexture('assets/DejaVuSansMono.ttf', {fontName: 'DejaVuSansMono'});
Promise.<MsdfFontTextureAsset>Load a MSDF font texture asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<MsdfFontTextureAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL. |
| [params] | \* |
Optional params dictionary. See MsdfFontTextureAsset.load() for more details. |
Example
let fontTexture = await Shaku.assets.loadMsdfFontTexture('DejaVuSansMono.font', {jsonUrl: 'assets/DejaVuSansMono.json', textureUrl: 'assets/DejaVuSansMono.png'});
Promise.<JsonAsset>Load a json asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<JsonAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL. |
Example
let jsonData = await Shaku.assets.loadJson('assets/my_json_data.json');
console.log(jsonData.data);
Promise.<JsonAsset>Create a new json asset. If already exist, will reject promise.
Kind: instance method of Assets
Returns: Promise.<JsonAsset> - promise to resolve with asset instance, when ready. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| name | String |
Asset name (matched to URLs when using cache). If null, will not add to cache. |
| data | Object | String |
Optional starting data. |
Example
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
Promise.<BinaryAsset>Load a binary data asset. If already loaded, will use cache.
Kind: instance method of Assets
Returns: Promise.<BinaryAsset> - promise to resolve with asset instance, when loaded. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL. |
Example
let binData = await Shaku.assets.loadBinary('assets/my_bin_data.dat');
console.log(binData.data);
Promise.<BinaryAsset>Create a new binary asset. If already exist, will reject promise.
Kind: instance method of Assets
Returns: Promise.<BinaryAsset> - promise to resolve with asset instance, when ready. You can access the loading asset with .asset on the promise.
| Param | Type | Description |
|---|---|---|
| name | String |
Asset name (matched to URLs when using cache). If null, will not add to cache. |
| data | Array.<Number> | Uint8Array |
Binary data to set. |
Example
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
Destroy and free asset from cache.
Kind: instance method of Assets
| Param | Type | Description |
|---|---|---|
| url | String |
Asset URL to free. |
Example
Shaku.assets.free("my_asset_url");
Free all loaded assets from cache.
Kind: instance method of Assets
Example
Shaku.assets.clearCache();
A loadable binary data asset. This asset type loads array of bytes from a remote file.
Kind: global class
Uint8ArrayPromisePromiseStringKind: instance property of BinaryAsset
Uint8ArrayGet binary data.
Kind: instance property of BinaryAsset
Returns: Uint8Array - Data as bytes array.
PromiseLoad the binary data from the asset URL.
Kind: instance method of BinaryAsset
Returns: Promise - Promise to resolve when fully loaded.
PromiseCreate the binary data asset from array or Uint8Array.
Kind: instance method of BinaryAsset
Returns: Promise - Promise to resolve when asset is ready.
| Param | Type | Description |
|---|---|---|
| source | Array.<Number> | Uint8Array |
Data to create asset from. |
Kind: instance method of BinaryAsset
StringConvert and return data as string.
Kind: instance method of BinaryAsset
Returns: String - Data converted to string.
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
NumberNumberPromiseVector2RectangleVector2NumberGet line height.
Kind: instance property of FontTextureAsset
Get font name.
Kind: instance property of FontTextureAsset
Get font size.
Kind: instance property of FontTextureAsset
Get placeholder character.
Kind: instance property of FontTextureAsset
Get the texture.
Kind: instance property of FontTextureAsset
NumberGet texture width.
Kind: instance property of FontTextureAsset
Returns: Number - Texture width.
NumberGet texture height.
Kind: instance property of FontTextureAsset
Returns: Number - Texture height.
Kind: instance property of FontTextureAsset
PromiseGenerate the font texture from a font found in given URL.
Kind: instance method of FontTextureAsset
Returns: Promise - Promise to resolve when fully loaded.
| Param | Type | Description |
|---|---|---|
| params | \* |
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. |
Vector2Get texture size as a vector.
Kind: instance method of FontTextureAsset
Returns: Vector2 - Texture size.
RectangleGet the source rectangle for a given character in texture.
Kind: instance method of FontTextureAsset
Returns: Rectangle - Source rectangle for character.
| Param | Type | Description |
|---|---|---|
| character | Character |
Character to get source rect for. |
Vector2When drawing the character, get the offset to add to the cursor.
Kind: instance method of FontTextureAsset
Returns: Vector2 - Offset to add to the cursor before drawing the character.
| Param | Type | Description |
|---|---|---|
| character | Character |
Character to get the offset for. |
NumberGet how much to advance the cursor when drawing this character.
Kind: instance method of FontTextureAsset
Returns: Number - Distance to move the cursor after drawing the character.
| Param | Type | Description |
|---|---|---|
| character | Character |
Character to get the advance for. |
Kind: instance method of FontTextureAsset
A loadable json asset. This asset type loads JSON from a remote file.
Kind: global class
\*PromisePromise\*Get json data.
Kind: instance property of JsonAsset
Returns: \* - Data as dictionary.
Kind: instance property of JsonAsset
PromiseLoad the JSON data from the asset URL.
Kind: instance method of JsonAsset
Returns: Promise - Promise to resolve when fully loaded.
PromiseCreate the JSON data asset from object or string.
Kind: instance method of JsonAsset
Returns: Promise - Promise to resolve when asset is ready.
| Param | Type | Description |
|---|---|---|
| source | Object | String |
Data to create asset from. |
Kind: instance method of JsonAsset
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
NumberNumberPromiseVector2NumberGet texture width.
Kind: instance property of MsdfFontTextureAsset
Returns: Number - Texture width.
NumberGet texture height.
Kind: instance property of MsdfFontTextureAsset
Returns: Number - Texture height.
PromiseGenerate the font metadata and texture from the given URL.
Kind: instance method of MsdfFontTextureAsset
Returns: Promise - Promise to resolve when fully loaded.
| Param | Type | Description |
|---|---|---|
| params | \* |
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. |
Vector2Get texture size as a vector.
Kind: instance method of MsdfFontTextureAsset
Returns: Vector2 - Texture size.
Kind: instance method of MsdfFontTextureAsset
Kind: instance method of MsdfFontTextureAsset
Kind: instance method of MsdfFontTextureAsset
A loadable sound asset. This is the asset type you use to play sounds.
Kind: global class
PromiseKind: instance property of SoundAsset
PromiseLoad 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 SoundAsset
Returns: Promise - Promise to resolve when fully loaded.
Kind: instance method of SoundAsset
A loadable texture asset. This asset type loads an image from URL or source, and turn it into a texture.
Kind: global class
PromisePromiseColorArray.<Array.<Color>>Kind: instance property of TextureAsset
Kind: instance property of TextureAsset
Kind: instance property of TextureAsset
Kind: instance property of TextureAsset
Kind: instance property of TextureAsset
PromiseLoad the texture from it’s image URL.
Kind: instance method of TextureAsset
Returns: Promise - Promise to resolve when fully loaded.
| Param | Type | Description |
|---|---|---|
| params | \* |
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. |
Create this texture as an empty render target.
Kind: instance method of TextureAsset
| Param | Type | Description |
|---|---|---|
| width | Number |
Texture width. |
| height | Number |
Texture height. |
| channels | Number |
Texture channels count. Defaults to 4 (RGBA). |
Create texture from loaded image instance.
Kind: instance method of TextureAsset
See: TextureAsset.load for params.
| Param | Type | Description |
|---|---|---|
| image | Image |
Image to create texture from. Image must be loaded! |
| params | \* |
Optional additional params. See load() for details. |
PromiseCreate the texture from an image.
Kind: instance method of TextureAsset
Returns: Promise - Promise to resolve when asset is ready.
See: TextureAsset.load for params.
| Param | Type | Description |
|---|---|---|
| source | Image | String |
Image or Image source URL to create texture from. |
| params | \* |
Optional additional params. See load() for details. |
ColorGet 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 TextureAsset
Returns: Color - Pixel color.
| Param | Type | Description |
|---|---|---|
| x | Number |
Pixel X value. |
| y | Number |
Pixel Y value. |
Array.<Array.<Color>>Get a 2D array with pixel colors.
Kind: instance method of TextureAsset
Returns: Array.<Array.<Color>> - A 2D array with all texture pixel colors.
| Param | Type | Description |
|---|---|---|
| [x] | Number |
Offset X in texture to get. Defaults to 0. |
| [y] | Number |
Offset Y in texture to get. Defaults to 0. |
| [width] | Number |
How many pixels to get on X axis. Defaults to texture width - x. |
| [height] | Number |
How many pixels to get on Y axis. Defaults to texture height - y. |
Kind: instance method of TextureAsset
Base type for all texture asset types.
Kind: global class
ImageNumberNumberVector2Get texture magnifying filter, or null to use default.
Kind: instance property of TextureAssetBase
See: Shaku.gfx.TextureFilterModes
Set texture magnifying filter.
Kind: instance property of TextureAssetBase
See: Shaku.gfx.TextureFilterModes
| Param | Type | Description |
|---|---|---|
| value | TextureFilterMode |
Filter mode to use or null to use default. |
Get texture wrapping mode, or null to use default.
Kind: instance property of TextureAssetBase
See: Shaku.gfx.TextureWrapModes
Set texture wrapping mode.
Kind: instance property of TextureAssetBase
See: Shaku.gfx.TextureWrapModes
| Param | Type | Description |
|---|---|---|
| value | TextureWrapMode |
Wrapping mode to use or null to use default. |
ImageGet raw image.
Kind: instance property of TextureAssetBase
Returns: Image - Image instance.
NumberGet texture width.
Kind: instance property of TextureAssetBase
Returns: Number - Texture width.
NumberGet texture height.
Kind: instance property of TextureAssetBase
Returns: Number - Texture height.
Get texture instance for WebGL.
Kind: instance property of TextureAssetBase
Vector2Get texture size as a vector.
Kind: instance method of TextureAssetBase
Returns: Vector2 - Texture size.
A texture atlas we can build at runtime to combine together multiple textures.
Kind: global class
Array.<TextureAsset>Get a list with all textures in atlas.
Kind: instance property of TextureAtlasAsset
Returns: Array.<TextureAsset> - Textures in atlas.
Kind: instance property of TextureAtlasAsset
TextureInAtlasAssetGet texture asset and source rectangle for a desired image URL.
Kind: instance method of TextureAtlasAsset
Returns: TextureInAtlasAsset - Texture in atlas asset, or null if not found.
| Param | Type | Description |
|---|---|---|
| url | String |
URL to fetch texture and source from. Can be full URL, relative URL, or absolute URL starting from /. |
Kind: instance method of TextureAtlasAsset
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.
Kind: global class
RectangleReturn the source rectangle in texture atlas.
Kind: instance property of TextureInAtlasAsset
Returns: Rectangle - Source rectangle.
RectangleReturn the source rectangle in texture atlas, in normalized 0.0-1.0 values.
Kind: instance property of TextureInAtlasAsset
Returns: Rectangle - Source rectangle.
TextureAssetReturn the texture asset of this atlas texture.
Kind: instance property of TextureInAtlasAsset
Returns: TextureAsset - Texture asset.
TextureAtlasAssetReturn the texture atlas class.
Kind: instance property of TextureInAtlasAsset
Returns: TextureAtlasAsset - Parent atlas.
Kind: instance property of TextureInAtlasAsset
Kind: instance property of TextureInAtlasAsset
Kind: instance property of TextureInAtlasAsset
Kind: instance property of TextureInAtlasAsset
Kind: instance property of TextureInAtlasAsset
Kind: instance method of TextureInAtlasAsset
Collision is the collision manager. It provides basic 2d collision detection functionality. Note: this is not a physics engine, its only for detection and objects picking.
To access the Collision manager you use Shaku.collision.
Kind: global class
Create the manager.
The collision resolver we use to detect collision between different shapes. You can use this object directly without creating a collision world, if you just need to test collision between shapes.
Kind: instance property of Collision
Get the collision reactanle shape class.
Kind: instance property of Collision
Get the collision point shape class.
Kind: instance property of Collision
Get the collision circle shape class.
Kind: instance property of Collision
Get the collision lines shape class.
Kind: instance property of Collision
Get the tilemap collision shape class.
Kind: instance property of Collision
CollisionWorldCreate a new collision world object.
Kind: instance method of Collision
Returns: CollisionWorld - Newly created collision world.
| Param | Type | Description |
|---|---|---|
| gridCellSize | Number | Vector2 |
Collision world grid cell size. |
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.
Kind: global class
\*CollisionTestResultArray.<CollisionTestResult>Array.<CollisionShape>ShapesBatchCreate the collision world.
| Param | Type | Description |
|---|---|---|
| resolver | CollisionResolver |
Collision resolver to use for this world. |
| gridCellSize | Number | Vector2 |
For optimize collision testing, the collision world is divided into a collision grid. This param determine the grid cell size. |
Collision resolver used in this collision world. By default, will inherit the collision manager default resolver.
Kind: instance property of CollisionWorld
\*Get current stats.
Kind: instance property of CollisionWorld
Returns: \* - Dictionary with the following stats:
updatedShapes: number of times we updated or added new shapes.
addedShapes: number of new shapes added.
deletedGridCells: grid cells that got deleted after they were empty.
createdGridCell: new grid cells created.
broadPhaseShapesChecksPrePredicate: how many shapes were tested in a broadphase check, before the predicate method was called.
broadPhaseShapesChecksPostPredicate: how many shapes were tested in a broadphase check, after the predicate method was called.
broadPhaseCalls: how many broadphase calls were made
collisionChecks: how many shape-vs-shape collision checks were actually made.
collisionMatches: how many collision checks were positive.
Reset stats.
Kind: instance method of CollisionWorld
Iterate all shapes in world.
Kind: instance method of CollisionWorld
| Param | Type | Description |
|---|---|---|
| callback | function |
Callback to invoke on all shapes. Return false to break iteration. |
Add a collision shape to this world.
Kind: instance method of CollisionWorld
| Param | Type | Description |
|---|---|---|
| shape | CollisionShape |
Shape to add. |
Remove a collision shape from this world.
Kind: instance method of CollisionWorld
| Param | Type | Description |
|---|---|---|
| shape | CollisionShape |
Shape to remove. |
CollisionTestResultTest collision with shapes in world, and return just the first result found.
Kind: instance method of CollisionWorld
Returns: CollisionTestResult - A collision test result, or null if not found.
| Param | Type | Description |
|---|---|---|
| sourceShape | CollisionShape |
Source shape to check collision for. If shape is in world, it will not collide with itself. |
| sortByDistance | Boolean |
If true will return the nearest collision found (based on center of shapes). |
| mask | Number |
Optional mask of bits to match against shapes collisionFlags. Will only return shapes that have at least one common bit. |
| predicate | function |
Optional filter to run on any shape we’re about to test collision with. If the predicate returns false, we will skip this shape. |
Array.<CollisionTestResult>Test collision with shapes in world, and return all results found.
Kind: instance method of CollisionWorld
Returns: Array.<CollisionTestResult> - An array of collision test results, or empty array if none found.
| Param | Type | Description |
|---|---|---|
| sourceShape | CollisionShape |
Source shape to check collision for. If shape is in world, it will not collide with itself. |
| sortByDistance | Boolean |
If true will sort results by distance. |
| mask | Number |
Optional mask of bits to match against shapes collisionFlags. Will only return shapes that have at least one common bit. |
| predicate | function |
Optional filter to run on any shape we’re about to test collision with. If the predicate returns false, we will skip this shape. |
| intermediateProcessor | function |
Optional method to run after each positive result with the collision result as param. Return false to stop and return results. |
Array.<CollisionShape>Return array of shapes that touch a given position, with optional radius.
Kind: instance method of CollisionWorld
Returns: Array.<CollisionShape> - Array with collision shapes we picked.
| Param | Type | Description |
|---|---|---|
| position | \* |
Position to pick. |
| radius | \* |
Optional picking radius to use a circle instead of a point. |
| sortByDistance | \* |
If true, will sort results by distance from point. |
| mask | \* |
Collision mask to filter by. |
| predicate | \* |
Optional predicate method to filter by. |
Example
let shapes = world.pick(Shaku.input.mousePosition);
Set the shapes batch to use for debug-drawing this collision world.
Kind: instance method of CollisionWorld
| Param | Type | Description |
|---|---|---|
| batch | ShapesBatch |
Batch to use for debug draw. |
ShapesBatchReturn the currently set debug draw batch, or create a new one if needed.
Kind: instance method of CollisionWorld
Returns: ShapesBatch - Shapes batch instance used to debug-draw collision world.
Debug-draw the current collision world.
Kind: instance method of CollisionWorld
| Param | Type | Description |
|---|---|---|
| gridColor | Color |
Optional grid color (default to black). |
| gridHighlitColor | Color |
Optional grid color for cells with shapes in them (default to red). |
| opacity | Number |
Optional opacity factor (default to 0.5). |
| camera | Camera |
Optional camera for offset and viewport. |
The collision resolver is responsible to implement collision detection between pair of shapes of same or different types.
Kind: global class
Create the resolver.
Set the method used to test collision between two shapes. Note: you don’t need to register the same handler twice for reverse order, its done automatically inside.
Kind: instance method of CollisionResolver
| Param | Type | Description |
|---|---|---|
| firstShapeId | String |
The shape identifier the handler recieves as first argument. |
| secondShapeId | String |
The shape identifier the handler recieves as second argument. |
| handler | function |
Method to test collision between the shapes. Return false if don’t collide, return either Vector2 with collision position or ‘true’ for collision. |
CollisionTestResultCheck a collision between two shapes.
Kind: instance method of CollisionResolver
Returns: CollisionTestResult - collision detection result or null if they don’t collide.
| Param | Type | Description |
|---|---|---|
| first | CollisionShape |
First collision shape to test. |
| second | CollisionShape |
Second collision shape to test. |
CollisionTestResultCheck a collision between two shapes.
Kind: instance method of CollisionResolver
Returns: CollisionTestResult - collision detection result or null if they don’t collide.
| Param | Type | Description |
|---|---|---|
| first | CollisionShape |
First collision shape to test. |
| second | CollisionShape |
Second collision shape to test. |
| handler | function |
Method to test collision between the shapes. |
Get handlers dictionary for a given shape.
Kind: instance method of CollisionResolver
Collision detection result.
Kind: global class
Create the collision result.
| Param | Type | Description |
|---|---|---|
| position | Vector2 |
Optional collision position. |
| first | CollisionShape |
First shape in the collision check. |
| second | CollisionShape |
Second shape in the collision check. |
Vector2Collision position, only relevant when there’s a single touching point. For shapes with multiple touching points, this will be null.
Kind: instance property of CollisionTestResult
CollisionShapeFirst collided shape.
Kind: instance property of CollisionTestResult
CollisionShapeSecond collided shape.
Kind: instance property of CollisionTestResult
Collision circle class.
Kind: global class
Create the collision shape.
| Param | Type | Description |
|---|---|---|
| circle | Circle |
the circle shape. |
Kind: instance property of CircleShape
Set this collision shape from circle.
Kind: instance method of CircleShape
| Param | Type | Description |
|---|---|---|
| circle | Circle |
Circle shape. |
Kind: instance method of CircleShape
Kind: instance method of CircleShape
Kind: instance method of CircleShape
Kind: instance method of CircleShape
Collision lines class. This shape is made of one line or more.
Kind: global class
Create the collision shape.
| Param | Type | Description |
|---|---|---|
| lines | Array.<Line> | Line |
Starting line / lines. |
Kind: instance property of LinesShape
Add line or lines to this collision shape.
Kind: instance method of LinesShape
| Param | Type | Description |
|---|---|---|
| lines | Array.<Line> | Line |
Line / lines to add. |
Set this shape from line or lines array.
Kind: instance method of LinesShape
| Param | Type | Description |
|---|---|---|
| lines | Array.<Line> | Line |
Line / lines to set. |
Kind: instance method of LinesShape
Kind: instance method of LinesShape
Kind: instance method of LinesShape
Kind: instance method of LinesShape
Collision point class.
Kind: global class
Create the collision shape.
| Param | Type | Description |
|---|---|---|
| position | Vector2 |
Point position. |
Kind: instance property of PointShape
Set this collision shape from vector2.
Kind: instance method of PointShape
| Param | Type | Description |
|---|---|---|
| position | Vector2 |
Point position. |
Vector2Get point position.
Kind: instance method of PointShape
Returns: Vector2 - Point position.
Kind: instance method of PointShape
Kind: instance method of PointShape
Kind: instance method of PointShape
Debug draw this shape.
Kind: instance method of PointShape
| Param | Type | Description |
|---|---|---|
| opacity | Number |
Shape opacity factor. |
Collision rectangle class.
Kind: global class
Create the collision shape.
| Param | Type | Description |
|---|---|---|
| rectangle | Rectangle |
the rectangle shape. |
Kind: instance property of RectangleShape
Set this collision shape from rectangle.
Kind: instance method of RectangleShape
| Param | Type | Description |
|---|---|---|
| rectangle | Rectangle |
Rectangle shape. |
Kind: instance method of RectangleShape
Kind: instance method of RectangleShape
Kind: instance method of RectangleShape
Kind: instance method of RectangleShape
Collision shape base class.
Kind: global class
Create the collision shape.
StringGet the collision shape’s unique identifier.
Kind: instance property of CollisionShape
Returns: String - Shape’s unique identifier
Get collision flags (matched against collision mask when checking collision).
Kind: instance property of CollisionShape
Set collision flags (matched against collision mask when checking collision).
Kind: instance property of CollisionShape
Set the debug color to use to draw this shape.
Kind: instance method of CollisionShape
| Param | Type | Description |
|---|---|---|
| color | Color |
Color to set or null to use default. |
Debug draw this shape.
Kind: instance method of CollisionShape
| Param | Type | Description |
|---|---|---|
| opacity | Number |
Shape opacity factor. |
| shapesBatch | ShapesBatch |
Optional shapes batch to use to debug draw the shape. By default will use the collision world. |
Vector2Get shape center position.
Kind: instance method of CollisionShape
Returns: Vector2 - Center position.
Remove self from parent world object.
Kind: instance method of CollisionShape
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.
Kind: global class
RectangleShapeArray.<RectangleShape>Create the collision tilemap.
| Param | Type | Description |
|---|---|---|
| offset | Vector2 |
Tilemap top-left corner. |
| gridSize | Vector2 |
Number of tiles on X and Y axis. |
| tileSize | Vector2 |
The size of a single tile. |
| borderThickness | Number |
Set a border collider with this thickness. |
Kind: instance property of TilemapShape
Set the state of a tile.
Kind: instance method of TilemapShape
| Param | Type | Description |
|---|---|---|
| index | Vector2 |
Tile index. |
| haveCollision | Boolean |
Does this tile have collision? |
| collisionFlags | Number |
Optional collision flag to set for this tile. |
RectangleShapeGet the collision shape of a tile at a given position.
Kind: instance method of TilemapShape
Returns: RectangleShape - Collision shape at this position, or null if not set.
| Param | Type | Description |
|---|---|---|
| position | Vector2 |
Position to get tile at. |
Iterate all tiles in given region, represented by a rectangle.
Kind: instance method of TilemapShape
| Param | Type | Description |
|---|---|---|
| region | Rectangle |
Rectangle to get tiles for. |
| callback | function |
Method to invoke for every tile. Return false to break iteration. |
Array.<RectangleShape>Get all tiles in given region, represented by a rectangle.
Kind: instance method of TilemapShape
Returns: Array.<RectangleShape> - Array with rectangle shapes or empty if none found.
| Param | Type | Description |
|---|---|---|
| region | Rectangle |
Rectangle to get tiles for. |
Kind: instance method of TilemapShape
Kind: instance method of TilemapShape
Kind: instance method of TilemapShape
Kind: instance method of TilemapShape
Implements a Camera object.
Kind: global class
Create the camera.
| Param | Type | Description |
|---|---|---|
| gfx | Gfx |
The gfx manager instance. |
RectangleGet camera’s viewport (drawing region to set when using this camera).
Kind: instance property of Camera
Returns: Rectangle - Camera’s viewport as rectangle.
Set camera’s viewport.
Kind: instance property of Camera
| Param | Type | Description |
|---|---|---|
| viewport | Rectangle |
New viewport to set or null to not use any viewport when using this camera. |
RectangleGet the region this camera covers.
Kind: instance method of Camera
Returns: Rectangle - region this camera covers.
Make this camera an orthographic camera with offset.
Kind: instance method of Camera
| Param | Type | Description |
|---|---|---|
| offset | Vector2 |
Camera offset (top-left corner). |
| ignoreViewportSize | Boolean |
If true, will take the entire canvas size for calculation and ignore the viewport size, if set. |
| near | Number |
Near clipping plane. |
| far | Number |
Far clipping plane. |
Make this camera an orthographic camera.
Kind: instance method of Camera
| Param | Type | Description |
|---|---|---|
| region | Rectangle |
Camera left, top, bottom and right. If not set, will take entire canvas. |
| near | Number |
Near clipping plane. |
| far | Number |
Far clipping plane. |
Implements a 3d Camera object.
Kind: global class
Create the camera.
| Param | Type | Description |
|---|---|---|
| gfx | Gfx |
The gfx manager instance. |
Camera projection matrix. You can set it manually, or use ‘orthographicOffset’ / ‘orthographic’ / ‘perspective’ helper functions.
Kind: instance property of Camera3D
Camera view matrix. You can set it manually, or use ‘setViewLookat’ helper function.
Kind: instance property of Camera3D
FrustumCalc and return the currently-visible view frustum, based on active camera.
Kind: instance method of Camera3D
Returns: Frustum - Visible frustum.
Set camera view matrix from source position and lookat.
Kind: instance method of Camera3D
| Param | Type | Description |
|---|---|---|
| [eyePosition] | Vector3 |
Camera source position. |
| [lookAt] | Vector3 |
Camera look-at target. |
Vector3Get 3d direction vector of this camera.
Kind: instance method of Camera3D
Returns: Vector3 - 3D direction vector.
MatrixGet view projection matrix.
Kind: instance method of Camera3D
Returns: Matrix - View-projection matrix.
MatrixGet projection view matrix.
Kind: instance method of Camera3D
Returns: Matrix - Projection-view matrix.
Make this camera a perspective camera.
Kind: instance method of Camera3D
| Param | Type | Description |
|---|---|---|
| fieldOfView | \* |
Field of view angle in radians. |
| aspectRatio | \* |
Aspect ratio. |
| near | \* |
Near clipping plane. |
| far | \* |
Far clipping plane. |
Vector3Unproject a 2d vector into 3D space. You can use this method to get the 3D direction the user points on with the mouse.
Kind: instance method of Camera3D
Returns: Vector3 - Unprojected point in 3D space.
| Param | Type | Default | Description |
|---|---|---|---|
| point | Vector2 |
Vector to unproject. | |
| zDistance | Number |
0 |
Distance from camera to locate the 3D point at (0 = near plane, 1 = far plane). |
Base class for a drawing batch, used to draw a collection of sprites or shapes.
Kind: global class
Create the draw batch.
EffectGet the default effect to use for this drawing batch type.
Kind: instance property of DrawBatch
Returns: Effect - Default effect to use for this drawing batch.
Get the BuffersUsage enum.
Kind: instance property of DrawBatch
See: BuffersUsage
BooleanReturn if the batch was destroyed.
Kind: instance property of DrawBatch
Returns: Boolean - True if batch was destoryed.
BooleanReturn if the batch is currently drawing.
Kind: instance property of DrawBatch
Returns: Boolean - If the batch began drawing.
BooleanReturn if this batch was turned static.
Kind: instance property of DrawBatch
Returns: Boolean - True if its a static batch you can no longer change.
Get the default blend mode to use for this drawing batch.
Kind: instance property of DrawBatch
Make the batch buffers static. This means you won’t be able to change the drawings in this batch once end() is called, but you’ll be able to redraw the batch with different effects and transformations without copying any data, and much faster. This also free up some internal arrays, thus reducing the memory used for this batch. Note: must be called after ‘begin()’ and right before the ‘end()’ call.
Kind: instance method of DrawBatch
Destroy the batch and free any resources assigned to it.
Kind: instance method of DrawBatch
Set the way we mark the buffers we pass to the GPU based on expected behavior. Use StreamDraw if you want to set buffers once, and use them in GPU few times. Use DynamicDraw if you want to set buffers many times, and use them in GPU many times. Use StaticDraw if you want to set buffers once, and use them in GPU many times.
Kind: instance method of DrawBatch
| Param | Type | Description |
|---|---|---|
| usage | BuffersUsage |
Buffers usage. |
Start drawing this batch. You must call this before doing any draw calls.
Kind: instance method of DrawBatch
| Param | Type | Description |
|---|---|---|
| [blendMode] | BlendModes |
Blend mode to draw this batch in. |
| [effect] | Effect |
Effect to use. If not defined will use this batch type default effect. |
| [transform] | Matrix |
Optional transformations to apply on all sprites. |
| [overrideEffectFlags] | \* |
Optional flags to override effect’s defaults. Possible keys: {enableDepthTest, enableFaceCulling, enableStencilTest, enableDithering}. |
Finish drawing without presenting on screen.
Kind: instance method of DrawBatch
End drawing and present whatever left in buffers on screen.
Kind: instance method of DrawBatch
Draw whatever is currently in buffers without ending the draw batch.
Kind: instance method of DrawBatch
Clear this buffer from any drawings in it. Called internally if ‘preserveBuffers’ is not true.
Kind: instance method of DrawBatch
Colored lines renderer. Responsible to drawing a batch of line segments or strips.
Kind: global class
NumberNumberBooleanCreate the sprites batch.
| Param | Type | Description |
|---|---|---|
| [lineSegmentsCount] | Number |
Internal buffers size, in line segments count (line segment = 3 vertices). Bigger value = faster rendering but more RAM. |
Kind: instance property of LinesBatch
Kind: instance property of LinesBatch
NumberGet how many line segments are currently in batch.
Kind: instance property of LinesBatch
Returns: Number - Line segments in batch count.
NumberGet how many line segments this batch can contain.
Kind: instance property of LinesBatch
Returns: Number - Max line segments count.
BooleanCheck if this batch is full.
Kind: instance property of LinesBatch
Returns: Boolean - True if batch is full.
Kind: instance method of LinesBatch
Kind: instance method of LinesBatch
Push vertices to drawing batch.
Kind: instance method of LinesBatch
| Param | Type | Description |
|---|---|---|
| vertices | Array.<Vertex> |
Vertices to push. Vertices count must be dividable by 3 to keep the batch consistent of polygons. |
Add a rectangle to draw.
Kind: instance method of LinesBatch
| Param | Type | Description |
|---|---|---|
| position | Vector2 | Vector3 |
Drawing position (at origin). If vector3 is provided, will pass z value to the shader code position attribute. |
| size | Vector2 | Vector3 | Number |
Drawing size. If vector3 is provided, will pass z value to the shader code position attribute for the bottom vertices, as position.z + size.z. |
| color | Color | Array.<Color> | undefined |
Rectangle color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate rectangle. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
| [skew] | Vector2 |
Skew the drawing corners on X and Y axis, around the origin point. |
Add a rectangle that covers a given destination rectangle.
Kind: instance method of LinesBatch
| Param | Type | Description |
|---|---|---|
| destRect | Rectangle | Vector2 |
Destination rectangle to draw on. If vector is provided, will draw from 0,0 with vector as size. |
| [sourceRect] | Rectangle |
Source rectangle, or undefined to use the entire texture. |
| color | Color | Array.<Color> | undefined |
Rectangle color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate rectangle. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
Draw a colored circle.
Kind: instance method of LinesBatch
| Param | Type | Description |
|---|---|---|
| circle | Circle |
Circle to draw. |
| color | Color |
Circle fill color. |
| [segmentsCount] | Number |
How many segments to build the circle from (more segments = smoother circle). |
| ratio | Number | Vector2 |
If procided, will scale the circle on X and Y axis to turn it into an oval. If a number is provided, will use this number to scale Y axis. |
| [rotation] | Number |
If provided will rotate the oval / circle. |
Colored shapes renderer. Responsible to drawing a batch of basic geometric shapes with as little draw calls as possible.
Kind: global class
functionBooleanBooleanfunctionBooleanNumberNumberBooleanCreate the sprites batch.
| Param | Type | Description |
|---|---|---|
| [batchPolygonsCount] | Number |
Internal buffers size, in polygons count (polygon = 3 vertices). Bigger value = faster rendering but more RAM. |
functionOptional method to trigger when shapes batch overflows and can’t contain any more polygons.
Kind: instance property of ShapesBatch
BooleanIf true, will floor vertices positions before pushing them to batch.
Kind: instance property of ShapesBatch
BooleanIf true, will draw lines as a single lines strip.
Kind: instance property of ShapesBatch
functionOptional method to trigger when shapes batch overflows and can’t contain any more polygons.
Kind: instance property of ShapesBatch
BooleanIf true, will floor vertices positions before pushing them to batch.
Kind: instance property of ShapesBatch
Kind: instance property of ShapesBatch
Kind: instance property of ShapesBatch
NumberGet how many polygons are currently in batch.
Kind: instance property of ShapesBatch
Returns: Number - Polygons in batch count.
NumberGet how many polygons this sprite batch can contain.
Kind: instance property of ShapesBatch
Returns: Number - Max polygons count.
BooleanCheck if this batch is full.
Kind: instance property of ShapesBatch
Returns: Boolean - True if batch is full.
Kind: instance method of ShapesBatch
Kind: instance method of ShapesBatch
Draw a line between two points. This method actually uses a rectangle internally, which is less efficient than using a proper LinesBatch, but have the advantage of supporting width.
Kind: instance method of ShapesBatch
| Param | Type | Description |
|---|---|---|
| fromPoint | Vector2 |
Starting position. |
| toPoint | Vector2 |
Ending position. |
| color | Color |
Line color. |
| [width] | Number |
Line width. |
Push vertices to drawing batch.
Kind: instance method of ShapesBatch
| Param | Type | Description |
|---|---|---|
| vertices | Array.<Vertex> |
Vertices to push. Vertices count must be dividable by 3 to keep the batch consistent of polygons. |
Add a rectangle to draw.
Kind: instance method of ShapesBatch
| Param | Type | Description |
|---|---|---|
| position | Vector2 | Vector3 |
Drawing position (at origin). If vector3 is provided, will pass z value to the shader code position attribute. |
| size | Vector2 | Vector3 | Number |
Drawing size. If vector3 is provided, will pass z value to the shader code position attribute for the bottom vertices, as position.z + size.z. |
| color | Color | Array.<Color> | undefined |
Rectangle color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate rectangle. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
| [skew] | Vector2 |
Skew the drawing corners on X and Y axis, around the origin point. |
Adds a 1x1 point.
Kind: instance method of ShapesBatch
| Param | Type | Description |
|---|---|---|
| position | Vector2 | Vector3 |
Point position. |
| color | Color |
Point color. |
Add a rectangle that covers a given destination rectangle.
Kind: instance method of ShapesBatch
| Param | Type | Description |
|---|---|---|
| destRect | Rectangle | Vector2 |
Destination rectangle to draw on. If vector is provided, will draw from 0,0 with vector as size. |
| color | Color | Array.<Color> | undefined |
Rectangle color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate rectangle. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
Draw a colored circle.
Kind: instance method of ShapesBatch
| Param | Type | Description |
|---|---|---|
| circle | Circle |
Circle to draw. |
| color | Color |
Circle fill color. |
| [segmentsCount] | Number |
How many segments to build the circle from (more segments = smoother circle). |
| [outsideColor] | Color |
If provided, will create a gradient-colored circle and this value will be the outter side color. |
| ratio | Number | Vector2 |
If procided, will scale the circle on X and Y axis to turn it into an oval. If a number is provided, will use this number to scale Y axis. |
| [rotation] | Number |
If provided will rotate the oval / circle. |
Sprite batch renderer. Responsible to drawing a batch of sprites with as little draw calls as possible.
Kind: global class
functionfunctionBooleanBooleanCreate the sprites batch.
| Param | Type | Description |
|---|---|---|
| [batchSpritesCount] | Number |
Internal buffers size, in sprites count (sprite = 4 vertices). Bigger value = faster rendering but more RAM. |
| [enableVertexColor] | Boolean |
If true (default) will support vertex color. |
| [enableNormals] | Boolean |
If true (not default) will support vertex normals. |
| [enableBinormals] | Boolean |
If true (not default) will support vertex binormals. |
| [enableTangents] | Boolean |
If true (not default) will support vertex tangents. |
Kind: instance property of SpriteBatch
functionOptional method to trigger when sprite batch overflows and can’t contain any more quads.
Kind: instance property of SpriteBatch
functionOptional method to trigger right before drawing this batch. Receive params: effect, texture.
Kind: instance property of SpriteBatch
BooleanIf true, will floor vertices positions before pushing them to batch.
Kind: instance property of SpriteBatch
BooleanIf true, will cull quads that are not visible in screen when adding them by default. Note: will cull based on screen region during the time of adding sprite, not the time of actually rendering it.
Kind: instance property of SpriteBatch
Push vertices to drawing batch.
Kind: instance method of SpriteBatch
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Texture to draw. |
| vertices | Array.<Vertex> |
Vertices to push. Vertices count must be dividable by 4 to keep the batch consistent of quads. |
Add a quad to draw.
Kind: instance method of SpriteBatch
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Texture to draw. |
| position | Vector2 | Vector3 |
Drawing position (at origin). If vector3 is provided, will pass z value to the shader code position attribute. |
| size | Vector2 | Vector3 | Number |
Drawing size. If vector3 is provided, will pass z value to the shader code position attribute for the bottom vertices, as position.z + size.z. |
| sourceRectangle | Rectangle |
Source rectangle, or undefined to use the entire texture. |
| color | Color | Array.<Color> | undefined |
Tint color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate sprite. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
| [skew] | Vector2 |
Skew the drawing corners on X and Y axis, around the origin point. |
Add sprites group to this batch.
Kind: instance method of SpriteBatch
| Param | Type | Description |
|---|---|---|
| group | SpritesGroup |
Sprite group to draw. |
| [cullOutOfScreen] | Boolean |
If true, will cull sprites that are not visible in currently set rendering region. |
Add a quad that covers a given destination rectangle.
Kind: instance method of SpriteBatch
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Texture to draw. |
| destRect | Rectangle | Vector2 |
Destination rectangle to draw on. If vector is provided, will draw from 0,0 with vector as size. |
| [sourceRect] | Rectangle |
Source rectangle, or undefined to use the entire texture. |
| color | Color | Array.<Color> | undefined |
Tint color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
3D Sprites batch renderer. Responsible to drawing 3D quads with textures on them.
Kind: global class
Create the 3d sprites batch.
| Param | Type | Description |
|---|---|---|
| [batchSpritesCount] | Number |
Internal buffers size, in sprites count (sprite = 4 vertices). Bigger value = faster rendering but more RAM. |
| [enableNormals] | Boolean |
If true (not default) will support vertex normals. |
| [enableBinormals] | Boolean |
If true (not default) will support vertex binormals. |
| [enableTangents] | Boolean |
If true (not default) will support vertex tangents. |
CameraGet camera instance.
Kind: instance property of SpriteBatch3D
Returns: Camera - Camera instance.
Kind: instance property of SpriteBatch3D
Kind: instance property of SpriteBatch3D
Set perspective camera.
Kind: instance method of SpriteBatch3D
| Param | Type | Description |
|---|---|---|
| [fieldOfView] | Number |
Camera field of view. |
| [aspectRatio] | Number |
Camera aspect ratio |
| [zNear] | Number |
Z near plane. |
| [zFar] | Number |
Z far plane. |
Set the camera for this batch.
Kind: instance method of SpriteBatch3D
| Param | Type | Description |
|---|---|---|
| camera | Camera |
Camera object to apply when drawing, or null if you want to set the camera manually. |
Base class for sprite-based rendering, ie vertices with textures.
Kind: global class
BooleanNumberNumberBooleanCreate the sprites batch.
| Param | Type | Description |
|---|---|---|
| [batchSpritesCount] | Number |
Internal buffers size, in sprites count (sprite = 4 vertices). Bigger value = faster rendering but more RAM. |
| [enableVertexColor] | Boolean |
If true (default) will support vertex color. |
| [enableNormals] | Boolean |
If true (not default) will support vertex normals. |
| [enableBinormals] | Boolean |
If true (not default) will support vertex binormals. |
| [enableTangents] | Boolean |
If true (not default) will support vertex tangents. |
Kind: instance property of SpriteBatchBase
BooleanGet if this sprite batch support vertex color.
Kind: instance property of SpriteBatchBase
Returns: Boolean - True if support vertex color.
Kind: instance property of SpriteBatchBase
NumberGet how many quads are currently in batch.
Kind: instance property of SpriteBatchBase
Returns: Number - Quads in batch count.
NumberGet how many quads this sprite batch can contain.
Kind: instance property of SpriteBatchBase
Returns: Number - Max quads count.
BooleanCheck if this batch is full.
Kind: instance property of SpriteBatchBase
Returns: Boolean - True if batch is full.
Kind: instance method of SpriteBatchBase
Kind: instance method of SpriteBatchBase
Add sprite or sprites to batch.
Kind: instance method of SpriteBatchBase
| Param | Type | Description |
|---|---|---|
| sprites | Sprite | Array.<Sprite> |
Sprite or multiple sprites to draw. |
| [transform] | Matrix |
Optional transformations to apply on sprite vertices. Won’t apply on static sprites. |
| [cullOutOfScreen] | Boolean |
If true, will cull sprites that are not visible in currently set rendering region. |
Text sprite batch renderer. Responsible to drawing a batch of characters sprites.
Kind: global class
Create the text sprites batch.
| Param | Type | Description |
|---|---|---|
| [batchSpritesCount] | Number |
Internal buffers size, in sprites count (sprite = 4 vertices). Bigger value = faster rendering but more RAM. |
BooleanIf true, will render as Msdf Fonts.
Kind: instance property of TextSpriteBatch
NumberIf bigger than 0, will draw outline. Currently not supported with msdf fonts. Must be set before begin() is called.
Kind: instance property of TextSpriteBatch
ColorOutline color, when outlineWeight is set. Must be set before begin() is called.
Kind: instance property of TextSpriteBatch
Kind: instance property of TextSpriteBatch
Add text sprites group to batch.
Kind: instance method of TextSpriteBatch
| Param | Type | Description |
|---|---|---|
| textGroup | SpritesGroup |
Text sprite group to draw. |
| cullOutOfScreen | Boolean |
If true, will cull out sprites that are not visible in screen. |
Effect base class. An effect = vertex shader + fragment shader + uniforms & attributes + setup code.
Kind: global class
\*\*StringStringBoolean | \*BooleanBoolean\*Create the effect.
\*Get a dictionary with all shaders uniforms. Key = uniform name, as appears in shader code. Value = { type: UniformTypes to represent uniform type, bind: Optional bind to one of the built-in uniforms. See Effect.UniformBinds for details. }
Kind: instance property of Effect
Returns: \* - Dictionary with uniforms descriptions.
\*Get a dictionary with all shader attributes. Key = attribute name, as appears in shader code. Value = { size: size of every value in this attribute. type: attribute type. See Effect.AttributeTypes for details. normalize: if true, will normalize values. stride: optional stride. offset: optional offset. bind: Optional bind to one of the built-in attributes. See Effect.AttributeBinds for details. }
Kind: instance property of Effect
Returns: \* - Dictionary with attributes descriptions.
StringGet this effect’s vertex shader code, as string.
Kind: instance property of Effect
Returns: String - Vertex shader code.
StringGet this effect’s fragment shader code, as string.
Kind: instance property of Effect
Returns: String - Fragment shader code.
Should this effect enable depth test?
Kind: instance property of Effect
Should this effect enable face culling?
Kind: instance property of Effect
Get depth func to use when rendering using this effect. Use ‘DepthFuncs’ to get options.
Kind: instance property of Effect
Should this effect enable stencil test?
Kind: instance property of Effect
Should this effect enable dithering?
Kind: instance property of Effect
Boolean | \*Get polygon offset factor, to apply on depth value before checking.
Kind: instance property of Effect
Returns: Boolean | \* - Return false to disable polygon offset, or {factor, unit} to apply polygon offset.
BooleanReturn if this effect have colors attribute on vertices.
Kind: instance property of Effect
Returns: Boolean - True if got vertices color attribute.
Make this effect active.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| overrideFlags | \* |
Optional flags to override in effect. May include the following: enableDepthTest, enableFaceCulling, enableStencilTest, enableDithering. |
Get a uniform method from a bind key.
Kind: instance method of Effect
Returns: Uniform set method, or null if not set.
| Param | Type | Description |
|---|---|---|
| bindKey | UniformBinds |
Uniform bind key. |
BooleanSet the main texture. Note: this will only work for effects that utilize the ‘MainTexture’ uniform.
Kind: instance method of Effect
Returns: Boolean - True if texture was changed, false if there was no need to change the texture.
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Texture to set. |
Set the main tint color. Note: this will only work for effects that utilize the ‘Color’ uniform.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| color | Color |
Color to set. |
Set the projection matrix uniform. Note: this will only work for effects that utilize the ‘Projection’ uniform.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| matrix | Matrix |
Matrix to set. |
Set the world matrix uniform. Note: this will only work for effects that utilize the ‘World’ uniform.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| matrix | Matrix |
Matrix to set. |
Set the view matrix uniform. Note: this will only work for effects that utilize the ‘View’ uniform.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| matrix | Matrix |
Matrix to set. |
Set outline params. Note: this will only work for effects that utilize the ‘OutlineWeight’ and ‘OutlineColor’ uniforms.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| weight | Number |
Outline weight, range from 0.0 to 1.0. |
| color | Color |
Outline color. |
Set a factor to normalize UV values to be 0-1. Note: this will only work for effects that utilize the ‘UvNormalizationFactor’ uniform.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| factor | Vector2 |
Normalize UVs factor. |
Set the vertices position buffer. Only works if there’s an attribute type bound to ‘Position’.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| buffer | WebGLBuffer |
Vertices position buffer. |
| forceSetBuffer | Boolean |
If true, will always set buffer even if buffer is currently set. |
Set the vertices texture coords buffer. Only works if there’s an attribute type bound to ‘TextureCoords’.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| buffer | WebGLBuffer |
Vertices texture coords buffer. |
| forceSetBuffer | Boolean |
If true, will always set buffer even if buffer is currently set. |
Set the vertices colors buffer. Only works if there’s an attribute type bound to ‘Colors’.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| buffer | WebGLBuffer |
Vertices colors buffer. |
| forceSetBuffer | Boolean |
If true, will always set buffer even if buffer is currently set. |
Set the vertices normals buffer. Only works if there’s an attribute type bound to ‘Normals’.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| buffer | WebGLBuffer |
Vertices normals buffer. |
| forceSetBuffer | Boolean |
If true, will always set buffer even if buffer is currently set. |
Set the vertices binormals buffer. Only works if there’s an attribute type bound to ‘Binormals’.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| buffer | WebGLBuffer |
Vertices binormals buffer. |
| forceSetBuffer | Boolean |
If true, will always set buffer even if buffer is currently set. |
Set the vertices tangents buffer. Only works if there’s an attribute type bound to ‘Tangents’.
Kind: instance method of Effect
| Param | Type | Description |
|---|---|---|
| buffer | WebGLBuffer |
Vertices tangents buffer. |
| forceSetBuffer | Boolean |
If true, will always set buffer even if buffer is currently set. |
\*Get all supported depth funcs we can set.
Kind: static property of Effect
Returns: \* - Depth func options: {Never, Less, Equal, LessEqual, Greater, GreaterEqual, Always, NotEqual}.
Default effect to draw MSDF font textures.
Kind: global class
Kind: instance property of MsdfFontEffect
Kind: instance property of MsdfFontEffect
Kind: instance property of MsdfFontEffect
Kind: instance property of MsdfFontEffect
Default basic effect to draw 2d shapes.
Kind: global class
Kind: instance property of ShapesEffect
Kind: instance property of ShapesEffect
Kind: instance property of ShapesEffect
Kind: instance property of ShapesEffect
Default basic effect to draw 2d sprites.
Kind: global class
Kind: instance property of SpritesEffect
Kind: instance property of SpritesEffect
Kind: instance property of SpritesEffect
Kind: instance property of SpritesEffect
Default basic effect to draw 2d sprites.
Kind: global class
Kind: instance property of Sprites3dEffect
Kind: instance property of Sprites3dEffect
Kind: instance property of Sprites3dEffect
Kind: instance property of Sprites3dEffect
Default basic effect to draw 2d sprites without vertex color.
Kind: global class
Kind: instance property of SpritesEffectNoVertexColor
Kind: instance property of SpritesEffectNoVertexColor
Kind: instance property of SpritesEffectNoVertexColor
Kind: instance property of SpritesEffectNoVertexColor
Default basic effect to draw 2d sprites with outline.
Kind: global class
Kind: instance property of SpritesWithOutlineEffect
Kind: instance property of SpritesWithOutlineEffect
Kind: instance property of SpritesWithOutlineEffect
Kind: instance property of SpritesWithOutlineEffect
Gfx is the graphics manager. Everything related to rendering and managing your game canvas goes here.
To access the Graphics manager you use Shaku.gfx.
Kind: global class
DictionaryTextureFilterModesTextureWrapModesTextureAssetNumberNumberHTMLCanvasElementNumberNumberNumberCameraCamera3DCameraRectangleVector2Vector2SpritesGroupBooleanCreate the manager.
DictionaryA dictionary containing all built-in effect instances.
Kind: instance property of Gfx
TextureFilterModesDefault texture filter to use when no texture filter is set.
Kind: instance property of Gfx
TextureWrapModesDefault wrap modes to use when no wrap mode is set.
Kind: instance property of Gfx
TextureAssetA 1x1 white texture.
Kind: instance property of Gfx
NumberGet the init WebGL version.
Kind: instance property of Gfx
Returns: Number - WebGL version number.
NumberMaximum number of vertices we allow when drawing lines.
Kind: instance property of Gfx
Returns: Number - max vertices per lines strip.
HTMLCanvasElementGet the canvas element controlled by the gfx manager.
If you didn’t provide your own canvas before initialization, you must add this canvas to your document after initializing Shaku.
Kind: instance property of Gfx
Returns: HTMLCanvasElement - Canvas we use for rendering.
Example
document.body.appendChild(Shaku.gfx.canvas);
Get the draw batch base class.
Kind: instance property of Gfx
See: DrawBatch
Get the sprites batch class.
Kind: instance property of Gfx
See: SpriteBatch
Get the 3d sprites batch class.
Kind: instance property of Gfx
See: SpriteBatch3D
Get the text sprites batch class.
Kind: instance property of Gfx
See: TextSpriteBatch
Get the shapes batch class.
Kind: instance property of Gfx
See: ShapesBatch
Get the lines batch class.
Kind: instance property of Gfx
See: LinesBatch
Get the Effect base class, which is required to implement custom effects.
Kind: instance property of Gfx
See: Effect
Get the default sprites effect class.
Kind: instance property of Gfx
See: SpritesEffect
Get the default sprites effect class that is used when vertex colors is disabled.
Kind: instance property of Gfx
See: SpritesEffectNoVertexColor
Get the default shapes effect class that is used to draw 2d shapes.
Kind: instance property of Gfx
See: ShapesEffect
Get the default 3d sprites effect class that is used to draw 3d textured quads.
Kind: instance property of Gfx
See: Sprites3dEffect
Get the Effect for rendering fonts with an MSDF texture.
Kind: instance property of Gfx
See: MsdfFontEffect
Get the sprite class.
Kind: instance property of Gfx
See: Sprite
Get the sprites group object.
Kind: instance property of Gfx
See: SpritesGroup
Get the matrix object.
Kind: instance property of Gfx
See: Matrix
Get the vertex object.
Kind: instance property of Gfx
See: Vertex
Get the text alignments options.
Kind: instance property of Gfx
See: TextAlignments
Get the blend modes enum.

Kind: instance property of Gfx
See: BlendModes
Get the wrap modes enum.

Kind: instance property of Gfx
See: TextureWrapModes
Get texture filter modes.

Kind: instance property of Gfx
See: TextureFilterModes
NumberGet number of actual WebGL draw calls we performed since the beginning of the frame.
Kind: instance property of Gfx
Returns: Number - Number of WebGL draw calls this frame.
NumberGet number of textured / colored quads we drawn since the beginning of the frame.
Kind: instance property of Gfx
Returns: Number - Number of quads drawn in this frame.
NumberGet number of shape polygons we drawn since the beginning of the frame.
Kind: instance property of Gfx
Returns: Number - Number of shape polygons drawn in this frame.
Set WebGL init flags (passed as additional params to the getContext() call). You must call this before initializing Shaku.
By default, Shaku will init WebGL context with the following flags:
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| flags | Dictionary |
WebGL init flags to set. |
Example
Shaku.gfx.setContextAttributes({ antialias: true, alpha: false });
Set the canvas element to initialize on. You must call this before initializing Shaku. Calling this will prevent Shaku from creating its own canvas.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| element | HTMLCanvasElement |
Canvas element to initialize on. |
Example
Shaku.gfx.setCanvas(document.getElementById('my-canvas'));
CameraCreate and return a new camera instance.
Kind: instance method of Gfx
Returns: Camera - New camera object.
| Param | Type | Description |
|---|---|---|
| withViewport | Boolean |
If true, will create camera with viewport value equal to canvas’ size. |
Camera3DCreate and return a new 3D camera instance.
Kind: instance method of Gfx
Returns: Camera3D - New camera object.
| Param | Type | Description |
|---|---|---|
| withViewport | Boolean |
If true, will create camera with viewport value equal to canvas’ size. |
CameraSet default orthographic camera from offset.
Kind: instance method of Gfx
Returns: Camera - Camera instance.
| Param | Type | Description |
|---|---|---|
| offset | Vector2 |
Camera top-left corner. |
Set resolution and canvas to the max size of its parent element or screen. If the canvas is directly under document body, it will take the max size of the page.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| [limitToParent] | Boolean |
if true, will use parent element size. If false, will stretch on entire document. |
| [allowOddNumbers] | Boolean |
if true, will permit odd numbers, which could lead to small artefacts when drawing pixel art. If false (default) will round to even numbers. |
Set a render target (texture) to render on.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| texture | TextureAsset | Array.<TextureAsset> | null |
Render target texture to set as render target, or null to reset and render back on canvas. Can also be array for multiple targets, which will take layouts 0-15 by their order. |
| [keepCamera] | Boolean |
If true, will keep current camera settings. If false (default) will reset camera. |
Example
// create render target
let renderTarget = await Shaku.assets.createRenderTarget('_my_render_target', 800, 600);
// use render target
Shaku.gfx.setRenderTarget(renderTarget);
// .. draw some stuff here
// reset render target and present it on screen
// note the negative height - render targets end up with flipped Y axis
Shaku.gfx.setRenderTarget(null);
Shaku.gfx.draw(renderTarget, new Shaku.utils.Vector2(screenX / 2, screenY / 2), new Shaku.utils.Vector2(screenX, -screenY));
Set resolution and canvas size.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| width | Number |
Resolution width. |
| height | Number |
Resolution height. |
| updateCanvasStyle | Boolean |
If true, will also update the canvas css size in pixels. |
Example
// set resolution and size of 800x600.
Shaku.gfx.setResolution(800, 600, true);
Reset camera properties to default camera.
Kind: instance method of Gfx
Set viewport, projection and other properties from a camera instance. Changing the camera properties after calling this method will not update the renderer, until you call applyCamera again.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| camera | Camera |
Camera to apply. |
RectangleGet current rendering region.
Kind: instance method of Gfx
Returns: Rectangle - Rectangle with rendering region.
| Param | Type | Description |
|---|---|---|
| includeOffset | Boolean |
If true (default) will include viewport offset, if exists. |
Vector2Get current rendering size. Unlike ‘canvasSize’, this takes viewport and render target into consideration.
Kind: instance method of Gfx
Returns: Vector2 - rendering size.
Vector2Get canvas size as vector.
Kind: instance method of Gfx
Returns: Vector2 - Canvas size.
SpritesGroupGenerate a sprites group to render a string using a font texture.
Take the result of this method and use with gfx.drawGroup() to render the text.
This is what you use when you want to draw texts with Shaku.
Note: its best to always draw texts with batching enabled.
Kind: instance method of Gfx
Returns: SpritesGroup - Sprites group containing the needed sprites to draw the given text with its properties.
| Param | Type | Description |
|---|---|---|
| fontTexture | FontTextureAsset |
Font texture asset to use. |
| text | String |
Text to generate sprites for. |
| [fontSize] | Number |
Font size, or undefined to use font texture base size. |
| color | Color | Array.<Color>= |
Text sprites color. If array is set, will assign each color to different vertex, starting from top-left. |
| [alignment] | TextAlignment |
Text alignment. |
| [offset] | Vector2 |
Optional starting offset. |
| [marginFactor] | Vector2 |
Optional factor for characters and line spacing. For example value of 2,1 will make double horizontal spacing. |
Example
// load font texture
let fontTexture = await Shaku.assets.loadFontTexture('assets/DejaVuSansMono.ttf', {fontName: 'DejaVuSansMono'});
// generate 'hello world!' text (note: you don't have to regenerate every frame if text didn't change)
let text1 = Shaku.gfx.buildText(fontTexture, "Hello World!");
text1.position.set(40, 40);
// draw text
Shaku.gfx.drawGroup(text1, true);
Make the renderer canvas centered.
Kind: instance method of Gfx
BooleanCheck if a given shape is currently in screen bounds, not taking camera into consideration.
Kind: instance method of Gfx
Returns: Boolean - True if given shape is in visible region.
| Param | Type | Description |
|---|---|---|
| shape | Circle | Vector | Rectangle | Line |
Shape to check. |
Make a given vector the center of the camera.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| position | Vector2 |
Camera position. |
| useCanvasSize | Boolean |
If true, will always use cancas size when calculating center. If false and render target is set, will use render target’s size. |
Clear screen to a given color.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| [color] | Color |
Color to clear screen to, or black if not set. |
Example
Shaku.gfx.clear(Shaku.utils.Color.cornflowerblue);
Clear depth buffer. Only relevant when depth is used.
Kind: instance method of Gfx
| Param | Type | Description |
|---|---|---|
| [value] | Number |
Value to clear depth buffer to. |
Sprite class.
Kind: global class
TextureAssetBaseVector2 | Vector3Vector2 | Vector3RectangleNumberVector2Vector2Color | Array.<Color>BooleanBooleanSpriteSpriteSpriteCreate the sprite object.
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Sprite texture. |
| [sourceRectangle] | Rectangle |
Optional source rectangle. |
TextureAssetBaseSprite’s texture.
Kind: instance property of Sprite
Vector2 | Vector3Sprite position. If Vector3 is provided, the z value will be passed to vertices position in shader code.
Kind: instance property of Sprite
Vector2 | Vector3Sprite size. If Vector3 is provided, the z value will be passed to the bottom vertices position in shader code, as position.z + size.z.
Kind: instance property of Sprite
RectangleSprite source rectangle in texture. Null will take entire texture.
Kind: instance property of Sprite
NumberSprite rotation in radians.
Kind: instance property of Sprite
Vector2Sprite origin point.
Kind: instance property of Sprite
Vector2Skew the sprite corners on X and Y axis, around the origin point.
Kind: instance property of Sprite
Color | Array.<Color>Sprite color. If array is set, will assign each color to different vertex, starting from top-left.
Kind: instance property of Sprite
BooleanCheck if this sprite is flipped around X axis. This is just a sugarcoat that returns if size.x < 0.
Kind: instance property of Sprite
Returns: Boolean - If sprite is flipped on X axis.
Flip sprite around X axis. This is just a sugarcoat that set size.x to negative or positive value, without changing its scale.
Kind: instance property of Sprite
| Param | Type | Description |
|---|---|---|
| flip | Boolean |
Should we flip the sprite around X axis. If undefined, will take the negative of flipX current value, ie will toggle flipping. |
BooleanCheck if this sprite is flipped around y axis. This is just a sugarcoat that returns if size.y < 0.
Kind: instance property of Sprite
Returns: Boolean - If sprite is flipped on Y axis.
Flip sprite around Y axis. This is just a sugarcoat that set size.y to negative or positive value, without changing its scale.
Kind: instance property of Sprite
| Param | Type | Description |
|---|---|---|
| flip | Boolean |
Should we flip the sprite around Y axis. If undefined, will take the negative of flipY current value, ie will toggle flipping. |
SpriteSet size to source rectangle size.
Kind: instance method of Sprite
Returns: Sprite - this.
SpriteSet size to texture size.
Kind: instance method of Sprite
Returns: Sprite - this.
Set the source Rectangle automatically from spritesheet. This method get sprite index in sheet and how many sprites there are in total, and calculate the desired offset and size in source Rectangle based on it + source image size.
Kind: instance method of Sprite
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Texture to set source rectangle from. |
| index | Vector2 |
Sprite index in spritesheet. |
| spritesCount | Vector2 |
How many sprites there are in spritesheet in total. |
| [margin] | Number |
How many pixels to trim from the tile (default is 0). |
| [setSize] | Boolean |
If true will also set width and height based on source rectangle (default is true). |
SpriteClone this sprite.
Kind: instance method of Sprite
Returns: Sprite - cloned sprite.
SpriteBuild a sprite from params.
Kind: static method of Sprite
Returns: Sprite - New sprite instance.
| Param | Type | Description |
|---|---|---|
| texture | TextureAssetBase |
Sprite texture. |
| position | Vector2 | Vector3 |
Drawing position (at origin). If vector3 is provided, will pass z value to the shader code position attribute. |
| size | Vector2 | Vector3 | Number |
Drawing size. If vector3 is provided, will pass z value to the shader code position attribute for the bottom vertices, as position.z + size.z. |
| sourceRectangle | Rectangle |
Source rectangle, or undefined to use the entire texture. |
| color | Color | Array.<Color> | undefined |
Tint color, or undefined to not change color. If array is set, will assign each color to different vertex, starting from top-left. |
| [rotation] | Number |
Rotate sprite. |
| [origin] | Vector2 |
Drawing origin. This will be the point at ‘position’ and rotation origin. |
| [skew] | Vector2 |
Skew the drawing corners on X and Y axis, around the origin point. |
Sprites group class. This object is a container to hold sprites collection + parent transformations. You need SpritesGroup to use batched rendering.
Kind: global class
Create the group object.
NumberSprites count in group.
Kind: instance property of SpritesGroup
Returns: Number - Number of sprites in group.
Iterate all sprites.
Kind: instance method of SpritesGroup
| Param | Type | Description |
|---|---|---|
| callback | function |
Callback to run on all sprites in group. |
Set color for all sprites in group.
Kind: instance method of SpritesGroup
| Param | Type | Description |
|---|---|---|
| color | Color |
Color to set. |
MatrixGet group’s transformations.
Kind: instance method of SpritesGroup
Returns: Matrix - Transformations matrix, or null if there’s nothing to apply.
SpriteAdds a sprite to group.
Kind: instance method of SpritesGroup
Returns: Sprite - The newly added sprite.
| Param | Type | Description |
|---|---|---|
| sprite | Sprite |
Sprite to add. |
Remove a sprite from group.
Kind: instance method of SpritesGroup
| Param | Type | Description |
|---|---|---|
| sprite | Sprite |
Sprite to remove. |
SpriteShift first sprite element.
Kind: instance method of SpritesGroup
Returns: Sprite - The removed sprite.
Sort sprites.
Kind: instance method of SpritesGroup
| Param | Type | Description |
|---|---|---|
| compare | function |
Comparer method. |
A vertex we can push to sprite batch.
Kind: global class
Create the vertex data.
| Param | Type | Description |
|---|---|---|
| position | Vector2 | Vector3 |
Vertex position. |
| textureCoord | Vector2 |
Vertex texture coord (in pixels). |
| color | Color |
Vertex color (undefined will default to white). |
| normal | Vector3 |
Vertex normal. |
VertexSet position.
Kind: instance method of Vertex
Returns: Vertex - this.
| Param | Type | Description |
|---|---|---|
| position | Vector2 | Vector3 |
Vertex position. |
| useRef | Boolean |
If true, will not clone the given position vector and use its reference instead. |
VertexSet texture coordinates.
Kind: instance method of Vertex
Returns: Vertex - this.
| Param | Type | Description |
|---|---|---|
| textureCoord | Vector2 |
Vertex texture coord (in pixels). |
| useRef | Boolean |
If true, will not clone the given coords vector and use its reference instead. |
VertexSet vertex color.
Kind: instance method of Vertex
Returns: Vertex - this.
| Param | Type | Description |
|---|---|---|
| color | Color |
Vertex color. |
| useRef | Boolean |
If true, will not clone the given color and use its reference instead. |
VertexSet vertex normal.
Kind: instance method of Vertex
Returns: Vertex - this.
| Param | Type | Description |
|---|---|---|
| normal | Vector3 |
Vertex normal. |
| useRef | Boolean |
If true, will not clone the given normal and use its reference instead. |
VertexSet vertex binormal.
Kind: instance method of Vertex
Returns: Vertex - this.
| Param | Type | Description |
|---|---|---|
| binormal | Vector3 |
Vertex binormal. |
| useRef | Boolean |
If true, will not clone the given binormal and use its reference instead. |
VertexSet vertex tangent.
Kind: instance method of Vertex
Returns: Vertex - this.
| Param | Type | Description |
|---|---|---|
| tangent | Vector3 |
Vertex tangent. |
| useRef | Boolean |
If true, will not clone the given tangent and use its reference instead. |
Gamepad data object. This object represents a snapshot of a gamepad state, it does not update automatically.
Kind: global class
StringVector2Vector2StringBooleanVector2Vector2BooleanBooleanFourButtonsClusterFourButtonsClusterFourButtonsClusterFrontButtonsBooleanNumberBooleanCreate gamepad state object.
| Param | Type | Description |
|---|---|---|
| gp | \* |
Browser gamepad state object. |
StringGamepad Id.
Kind: instance property of Gamepad
Vector2Gamepad first axis value.
Kind: instance property of Gamepad
Vector2Gamepad second axis value.
Kind: instance property of Gamepad
StringMapping type.
Kind: instance property of Gamepad
BooleanTrue if the gamepad is of a known type and we have extra mapped attributes. False if unknown / not supported.
Kind: instance property of Gamepad
Vector2Gamepad left stick. Only available with “standard” mapping.
Kind: instance property of Gamepad
Vector2Gamepad right stick. Only available with “standard” mapping.
Kind: instance property of Gamepad
BooleanGamepad left stick is pressed. Only available with “standard” mapping.
Kind: instance property of Gamepad
BooleanGamepad right stick is pressed. Only available with “standard” mapping.
Kind: instance property of Gamepad
FourButtonsClusterRight cluster button states.
Kind: instance property of Gamepad
FourButtonsClusterLeft cluster button states.
Kind: instance property of Gamepad
FourButtonsClusterCenter cluster button states.
Kind: instance property of Gamepad
FrontButtonsFront buttons states.
Kind: instance property of Gamepad
BooleanTrue if the gamepad is of a known type and we have extra mapped attributes. False if unknown.
Kind: instance property of Gamepad
NumberGet buttons count.
Kind: instance property of Gamepad
Returns: Number - Buttons count.
BooleanGet button state (if pressed down) by index.
Kind: instance method of Gamepad
Returns: Boolean - True if pressed, false otherwise.
| Param | Type | Description |
|---|---|---|
| index | Number |
Button index to check. |
Buttons cluster container - 4 buttons.
Create the cluster states.
| Param | Type | Description |
|---|---|---|
| bottom | Boolean |
Bottom button state. |
| right | Boolean |
Right button state. |
| left | Boolean |
Left button state. |
| top | Boolean |
Top button state. |
Buttons cluster container - 3 buttons.
Create the cluster states.
| Param | Type | Description |
|---|---|---|
| left | Boolean |
Left button state. |
| right | Boolean |
Right button state. |
| center | Boolean |
Center button state. |
Front buttons.
Create the cluster states.
Input manager. Used to recieve input from keyboard and mouse.
To access the Input manager use Shaku.input.
Kind: global class
BooleanBooleanBooleanBooleanBooleanBooleanNumberStringVector2BooleanBooleanBooleanVector2Vector2Vector2BooleanBooleanBooleanBooleanBooleanBooleanBooleanBooleanNumberNumberGamepadArray.<String>BooleanBooleanBooleanBooleanbooleanBooleanBooleanBooleanBooleanBooleanBooleanNumberNumberBooleanBooleanCreate the manager.
BooleanIf true, will prevent default input events by calling preventDefault().
Kind: instance property of Input
BooleanBy default, when holding wheel button down browsers will turn into special page scroll mode and will not emit mouse move events. if this property is set to true (default), the Input manager will prevent this behavior, so we could still get mouse delta while mouse wheel is held down.
Kind: instance property of Input
BooleanIf true (default), will disable the context menu (what typically opens when you right click the page).
Kind: instance property of Input
BooleanIf true (default), will treat touch events (touch start / touch end / touch move) as if the user clicked and moved a mouse.
Kind: instance property of Input
BooleanIf true (default), will delegate events from mapped gamepads to custom keys. This will add the following codes to all basic query methods (down, pressed, released, doublePressed, doubleReleased):
gamepad is the gamepad index: gamepad0, gamepad1, gamepad2..Kind: instance property of Input
BooleanIf true (default), will reset all states if the window loses focus.
Kind: instance property of Input
NumberDefault time, in milliseconds, to consider two consecutive key presses as a double-press.
Kind: instance property of Input
Get the Mouse Buttons enum.
Kind: instance property of Input
See: MouseButtons
Get the Keyboard Buttons enum.
Kind: instance property of Input
See: KeyboardKeys
StringReturn the string code to use in order to get touch events.
Kind: instance property of Input
Returns: String - Key code to use for touch events.
Vector2Get touch screen touching position. Note: if not currently touching, will return last known position.
Kind: instance property of Input
Returns: Vector2 - Touch position.
BooleanGet if currently touching a touch screen.
Kind: instance property of Input
Returns: Boolean - True if currently touching the screen.
BooleanGet if started touching a touch screen in current frame.
Kind: instance property of Input
Returns: Boolean - True if started touching the screen now.
BooleanGet if stopped touching a touch screen in current frame.
Kind: instance property of Input
Returns: Boolean - True if stopped touching the screen now.
Vector2Get mouse position.
Kind: instance property of Input
Returns: Vector2 - Mouse position.
Vector2Get mouse previous position (before the last endFrame() call).
Kind: instance property of Input
Returns: Vector2 - Mouse position in previous frame.
Vector2Get mouse movement since last endFrame() call.
Kind: instance property of Input
Returns: Vector2 - Mouse change since last frame.
BooleanGet if mouse is currently moving.
Kind: instance property of Input
Returns: Boolean - True if mouse moved since last frame, false otherwise.
BooleanGet if any of the shift keys are currently down.
Kind: instance property of Input
Returns: Boolean - True if there’s a shift key pressed down.
BooleanGet if any of the Ctrl keys are currently down.
Kind: instance property of Input
Returns: Boolean - True if there’s a Ctrl key pressed down.
BooleanGet if any of the Alt keys are currently down.
Kind: instance property of Input
Returns: Boolean - True if there’s an Alt key pressed down.
BooleanGet if any keyboard key was pressed this frame.
Kind: instance property of Input
Returns: Boolean - True if any key was pressed down this frame.
BooleanGet if any keyboard key is currently down.
Kind: instance property of Input
Returns: Boolean - True if there’s a key pressed down.
BooleanGet if any mouse button was pressed this frame.
Kind: instance property of Input
Returns: Boolean - True if any of the mouse buttons were pressed this frame.
BooleanGet if any mouse button is down.
Kind: instance property of Input
Returns: Boolean - True if any of the mouse buttons are pressed.
NumberGet mouse wheel sign.
Kind: instance property of Input
Returns: Number - Mouse wheel sign (-1 or 1) for wheel scrolling that happened during this frame.
Will return 0 if mouse wheel is not currently being used.
NumberGet mouse wheel value.
Kind: instance property of Input
Returns: Number - Mouse wheel value.
Set the target element to attach input to. If not called, will just use the entire document. Must be called before initializing Shaku. This can also be a method to invoke while initializing.
Kind: instance method of Input
| Param | Type | Description |
|---|---|---|
| element | Element | elementCallback |
Element to attach input to. |
Example
// the following will use whatever canvas the gfx manager uses as input element.
// this means mouse offset will also be relative to this element.
Shaku.input.setTargetElement(() => Shaku.gfx.canvas);
GamepadGet Gamepad current states, or null if not connected. Note: this object does not update itself, you’ll need to query it again every frame.
Kind: instance method of Input
Returns: Gamepad - Gamepad current state.
| Param | Type | Description |
|---|---|---|
| [index] | Number |
Gamepad index or undefined for first connected device. |
Get gamepad id, or null if not connected to this slot.
Kind: instance method of Input
Returns: Gamepad id or null.
| Param | Type | Description |
|---|---|---|
| [index] | Number |
Gamepad index or undefined for first connected device. |
Array.<String>Return a list with connected devices ids.
Kind: instance method of Input
Returns: Array.<String> - List of connected devices ids.
Set a custom key code state you can later use with all the built in methods (down / pressed / released / doublePressed, etc.)
For example, lets say you want to implement a simulated keyboard and use it alongside the real keyboard.
When your simulated keyboard space key is pressed, you can call setCustomState('sim_space', true). When released, call setCustomState('sim_space', false).
Now you can use Shaku.input.down(['space', 'sim_space']) to check if either a real space or simulated space is pressed down.
Kind: instance method of Input
| Param | Type | Description |
|---|---|---|
| code | String |
Code to set state for. |
| value | Boolean | null |
Current value to set, or null to remove custom key. |
BooleanGet if mouse button was pressed this frame.
Kind: instance method of Input
Returns: Boolean - True if mouse button is currently down, but was up in previous frame.
| Param | Type | Default | Description |
|---|---|---|---|
| button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
BooleanGet if mouse button is currently pressed.
Kind: instance method of Input
Returns: Boolean - true if mouse button is currently down, false otherwise.
| Param | Type | Default | Description |
|---|---|---|---|
| button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
BooleanGet if mouse button is currently not down.
Kind: instance method of Input
Returns: Boolean - true if mouse button is currently up, false otherwise.
| Param | Type | Default | Description |
|---|---|---|---|
| button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
BooleanGet if mouse button was released in current frame.
Kind: instance method of Input
Returns: Boolean - True if mouse was down last frame, but released in current frame.
| Param | Type | Default | Description |
|---|---|---|---|
| button | MouseButton |
0 |
Button code (defults to MouseButtons.left). |
booleanGet if keyboard key is currently pressed down.
Kind: instance method of Input
Returns: boolean - True if keyboard key is currently down, false otherwise.
| Param | Type | Description |
|---|---|---|
| key | KeyboardKey |
Keyboard key code. |
BooleanGet if keyboard key is currently not down.
Kind: instance method of Input
Returns: Boolean - True if keyboard key is currently up, false otherwise.
| Param | Type | Description |
|---|---|---|
| key | KeyboardKey |
Keyboard key code. |
BooleanGet if a keyboard button was released in current frame.
Kind: instance method of Input
Returns: Boolean - True if key was down last frame, but released in current frame.
| Param | Type | Description |
|---|---|---|
| button | KeyboardKey |
Keyboard key code. |
BooleanGet if keyboard key was pressed this frame.
Kind: instance method of Input
Returns: Boolean - True if key is currently down, but was up in previous frame.
| Param | Type | Description |
|---|---|---|
| key | KeyboardKey |
Keyboard key code. |
BooleanReturn if a mouse or keyboard button is currently down.
Kind: instance method of Input
Returns: Boolean - True if key or mouse button are down.
| Param | Type | Description |
|---|---|---|
| code | string | Array.<String> |
Keyboard, touch or mouse code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
Example
if (Shaku.input.down(['mouse_left', 'touch', 'space'])) { alert('mouse, touch screen or space are pressed!'); }
BooleanReturn if a mouse or keyboard button was released in this frame.
Kind: instance method of Input
Returns: Boolean - True if key or mouse button were down in previous frame, and released this frame.
| Param | Type | Description |
|---|---|---|
| code | string | Array.<String> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
Example
if (Shaku.input.released(['mouse_left', 'touch', 'space'])) { alert('mouse, touch screen or space were released!'); }
BooleanReturn if a mouse or keyboard button was pressed in this frame.
Kind: instance method of Input
Returns: Boolean - True if key or mouse button where up in previous frame, and pressed this frame.
| Param | Type | Description |
|---|---|---|
| code | string | Array.<String> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
Example
if (Shaku.input.pressed(['mouse_left', 'touch', 'space'])) { alert('mouse, touch screen or space were pressed!'); }
NumberReturn timestamp, in milliseconds, of the last time this key code was released.
Kind: instance method of Input
Returns: Number - Timestamp of last key release, or 0 if was never released.
| Param | Type | Description |
|---|---|---|
| code | string |
Keyboard, touch, gamepad or mouse button code. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
Example
let lastReleaseTime = Shaku.input.lastReleaseTime('mouse_left');
NumberReturn timestamp, in milliseconds, of the last time this key code was pressed.
Kind: instance method of Input
Returns: Number - Timestamp of last key press, or 0 if was never pressed.
| Param | Type | Description |
|---|---|---|
| code | string |
Keyboard, touch, gamepad or mouse button code. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
Example
let lastPressTime = Shaku.input.lastPressTime('mouse_left');
BooleanReturn if a key was double-pressed.
Kind: instance method of Input
Returns: Boolean - True if one or more key codes double-pressed, false otherwise.
| Param | Type | Description |
|---|---|---|
| code | string | Array.<string> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
| maxInterval | Number |
Max interval time, in milliseconds, to consider it a double-press. Defaults to defaultDoublePressInterval. |
Example
let doublePressed = Shaku.input.doublePressed(['mouse_left', 'touch', 'space']);
BooleanReturn if a key was double-released.
Kind: instance method of Input
Returns: Boolean - True if one or more key codes double-released, false otherwise.
| Param | Type | Description |
|---|---|---|
| code | string | Array.<string> |
Keyboard, touch, gamepad or mouse button code. Can be array of codes to test any of them. For mouse buttons: set code to ‘mouse_left’, ‘mouse_right’ or ‘mouse_middle’. For keyboard buttons: use one of the keys of KeyboardKeys (for example ‘a’, ‘alt’, ‘up_arrow’, etc..). For touch screen: set code to ‘touch’. For numbers (0-9): you can use the number itself. Note: if you inject any custom state via setCustomState(), you can use its code here too. |
| maxInterval | Number |
Max interval time, in milliseconds, to consider it a double-release. Defaults to defaultDoublePressInterval. |
Example
let doubleReleased = Shaku.input.doubleReleased(['mouse_left', 'touch', 'space']);
A logger manager. By default writes logs to console.
Kind: global class
Write a trace level log message.
Kind: instance method of Logger
| Param | Type | Description |
|---|---|---|
| msg | String |
Message to write. |
Write a debug level log message.
Kind: instance method of Logger
| Param | Type | Description |
|---|---|---|
| msg | String |
Message to write. |
Write an info level log message.
Kind: instance method of Logger
| Param | Type | Description |
|---|---|---|
| msg | String |
Message to write. |
Write a warning level log message.
Kind: instance method of Logger
| Param | Type | Description |
|---|---|---|
| msg | String |
Message to write. |
Write an error level log message.
Kind: instance method of Logger
| Param | Type | Description |
|---|---|---|
| msg | String |
Message to write. |
Set logger to throw an error every time a log message with severity higher than warning is written.
Kind: instance method of Logger
| Param | Type | Description |
|---|---|---|
| enable | Boolean |
Set to true to throw error on warnings. |
Interface for any manager. Manager = manages a domain in Shaku, such as gfx (graphics), sfx (sounds), input, etc.
Kind: global class
PromisePromiseInitialize the manager.
Kind: instance method of IManager
Returns: Promise - Promise to resolve when initialization is done.
Called every update at the begining of the frame.
Kind: instance method of IManager
Called every update at the end of the frame.
Kind: instance method of IManager
Destroy the manager.
Kind: instance method of IManager
Sfx manager. Used to play sound effects and music.
To access the Sfx manager use Shaku.sfx.
Kind: global class
Create the manager.
Get the SoundMixer class.
Kind: instance property of Sfx
See: SoundMixer
NumberGet currently playing sounds count.
Kind: instance property of Sfx
Returns: Number - Number of sounds currently playing.
NumberGet master volume. This affect all sound effects volumes.
Kind: instance property of Sfx
Returns: Number - Current master volume value.
Set master volume. This affect all sound effects volumes.
Kind: instance property of Sfx
| Param | Type | Description |
|---|---|---|
| value | Number |
Master volume to set. |
PromisePlay a sound once without any special properties and without returning a sound instance. Its a more convinient method to play sounds, but less efficient than ‘createSound()’ if you want to play multiple times.
Kind: instance method of Sfx
Returns: Promise - Promise to resolve when sound starts playing.
| Param | Type | Description |
|---|---|---|
| soundAsset | SoundAsset |
Sound asset to play. |
| volume | Number |
Volume to play sound (default to max). |
| playbackRate | Number |
Optional playback rate factor. |
| preservesPitch | Boolean |
Optional preserve pitch when changing rate factor. |
Example
let sound = await Shaku.assets.loadSound("assets/my_sound.ogg");
Shaku.sfx.play(sound, 0.75);
Stop all playing sounds.
Kind: instance method of Sfx
Example
Shaku.sfx.stopAll();
SoundInstanceCreate and return a sound instance you can use to play multiple times.
Kind: instance method of Sfx
Returns: SoundInstance - Newly created sound instance.
| Param | Type | Description |
|---|---|---|
| sound | SoundAsset |
Sound asset to play. |
Example
let sound = await Shaku.assets.loadSound("assets/my_sound.ogg");
let soundInstance = Shaku.sfx.createSound(sound);
soundInstance.play();
A sound effect instance you can play and stop.
Kind: global class
NumberBooleanBooleanNumberNumberNumberBooleanBooleanBooleanPromisePromiseBooleanCreate a sound instance.
| Param | Type | Description |
|---|---|---|
| sfxManager | Sfx |
Sfx manager instance. |
| url | String |
Sound URL or source. |
NumberGet sound effect playback rate.
Kind: instance property of SoundInstance
Returns: Number - Playback rate.
Set playback rate.
Kind: instance property of SoundInstance
| Param | Type | Description |
|---|---|---|
| val | Number |
Playback value to set. |
BooleanGet if to preserve pitch while changing playback rate.
Kind: instance property of SoundInstance
Returns: Boolean - Preserve pitch state of the sound instance.
Set if to preserve pitch while changing playback rate.
Kind: instance property of SoundInstance
| Param | Type | Description |
|---|---|---|
| val | Boolean |
New preserve pitch value to set. |
BooleanGet if playing in loop.
Kind: instance property of SoundInstance
Returns: Boolean - If this sound should play in loop.
Set if playing in loop.
Kind: instance property of SoundInstance
| Param | Type | Description |
|---|---|---|
| value | Boolean |
If this sound should play in loop. |
NumberGet volume.
Kind: instance property of SoundInstance
Returns: Number - Sound effect volume.
Set volume.
Kind: instance property of SoundInstance
| Param | Type | Description |
|---|---|---|
| value | Number |
Sound effect volume to set. |
NumberGet current time in track.
Kind: instance property of SoundInstance
Returns: Number - Current time in playing sound.
Set current time in track.
Kind: instance property of SoundInstance
| Param | Type | Description |
|---|---|---|
| value | Number |
Set current playing time in sound track. |
NumberGet track duration.
Kind: instance property of SoundInstance
Returns: Number - Sound duration in seconds.
BooleanGet if sound is currently paused.
Kind: instance property of SoundInstance
Returns: Boolean - True if sound is currently paused.
BooleanGet if sound is currently playing.
Kind: instance property of SoundInstance
Returns: Boolean - True if sound is currently playing.
BooleanGet if finished playing.
Kind: instance property of SoundInstance
Returns: Boolean - True if sound reached the end and didn’t loop.
Dispose the audio object when done playing the sound. This will call dispose() automatically when audio ends.
Kind: instance method of SoundInstance
Dispose the audio object and clear its resources. When playing lots of sounds its important to call dispose on sounds you no longer use, to avoid getting hit by “Blocked attempt to create a WebMediaPlayer” exception.
Kind: instance method of SoundInstance
PromisePlay sound.
Kind: instance method of SoundInstance
Returns: Promise - Promise to return when sound start playing.
Pause the sound.
Kind: instance method of SoundInstance
PromiseReplay sound from start.
Kind: instance method of SoundInstance
Returns: Promise - Promise to return when sound start playing.
BooleanStop the sound and go back to start.
Kind: instance method of SoundInstance
Returns: Boolean - True if successfully stopped sound, false otherwise.
A utility class to mix between two sounds.
Kind: global class
Create the sound mixer.
| Param | Type | Description |
|---|---|---|
| sound1 | SoundInstance |
Sound to mix from. Can be null to just fade in. |
| sound2 | SoundInstance |
Sound to mix to. Can be null to just fade out. |
| allowOverlapping | Boolean |
If true (default), will mix while overlapping sounds. If false, will first finish first sound before begining next. |
SoundInstanceGet first sound.
Kind: instance property of SoundMixer
Returns: SoundInstance - First sound instance.
SoundInstanceGet second sound.
Kind: instance property of SoundMixer
Returns: SoundInstance - Second sound instance.
NumberReturn current progress.
Kind: instance property of SoundMixer
Returns: Number - Mix progress from 0 to 1.
Stop both sounds.
Kind: instance method of SoundMixer
Update the mixer progress with time delta instead of absolute value.
Kind: instance method of SoundMixer
| Param | Type | Description |
|---|---|---|
| delta | Number |
Progress delta, in seconds. |
Update the mixer progress.
Kind: instance method of SoundMixer
| Param | Type | Description |
|---|---|---|
| progress | Number |
Transition progress from sound1 to sound2. Values must be between 0.0 to 1.0. |
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.
Kind: global class
UtilsSfxGfxInputAssetsCollisionBooleanBooleanBooleanGameTimeStringPromiseBooleanNumberNumberNumberLoggerCreate the Shaku main object.
UtilsDifferent utilities and framework objects, like vectors, rectangles, colors, etc.
Kind: instance property of Shaku
SfxSound effects and music manager.
Kind: instance property of Shaku
GfxGraphics manager.
Kind: instance property of Shaku
InputInput manager.
Kind: instance property of Shaku
AssetsAssets manager.
Kind: instance property of Shaku
CollisionCollision detection manager.
Kind: instance property of Shaku
BooleanIf true, will pause the updates and drawing calls when window is not focused. Will also not update elapsed time.
Kind: instance property of Shaku
BooleanSet to true to completely pause Shaku (will skip updates, drawing, and time counting).
Kind: instance property of Shaku
BooleanSet to true to pause just the game time. This will not pause real-life time. If you need real-life time stop please use the Python package.
Kind: instance property of Shaku
GameTimeGet current frame game time. Only valid between startFrame() and endFrame().
Kind: instance property of Shaku
Returns: GameTime - Current frame’s gametime.
StringGet Shaku’s version.
Kind: instance property of Shaku
Returns: String - Shaku’s version.
PromiseMethod to select managers to use + initialize them.
Kind: instance method of Shaku
Returns: Promise - promise to resolve when finish initialization.
| Param | Type | Description |
|---|---|---|
| [managers] | Array.<IManager> |
Array with list of managers to use or null to use all. |
Destroy all managers
Kind: instance method of Shaku
BooleanGet if the Shaku is currently paused, either because the ‘paused’ property is set, or because the document is not focused.
Kind: instance method of Shaku
Returns: Boolean - True if currently paused for any reason.
Start frame (update all managers).
Kind: instance method of Shaku
End frame (update all managers).
Kind: instance method of Shaku
Make Shaku run in silent mode, without logs. You can call this before init.
Kind: instance method of Shaku
Set logger to throw an error every time a log message with severity higher than warning is written. You can call this before init.
Kind: instance method of Shaku
| Param | Type | Description |
|---|---|---|
| enable | Boolean |
Set to true to throw error on warnings. |
NumberReturn current FPS count. Note: will return 0 until at least one second have passed.
Kind: instance method of Shaku
Returns: Number - FPS count.
NumberGet how long on average it takes to complete a game frame.
Kind: instance method of Shaku
Returns: Number - Average time, in milliseconds, it takes to complete a game frame.
NumberRequest animation frame with fallbacks.
Kind: instance method of Shaku
Returns: Number - Handle for cancellation.
| Param | Type | Description |
|---|---|---|
| callback | function |
Method to invoke in next animation frame. |
Cancel animation frame with fallbacks.
Kind: instance method of Shaku
| Param | Type | Description |
|---|---|---|
| id | Number |
Request handle. |
Set the logger writer class (will replace the default console output).
Kind: instance method of Shaku
| Param | Type | Description |
|---|---|---|
| loggerHandler | \* |
New logger handler (must implement trace, debug, info, warn, error methods). |
LoggerGet / create a custom logger.
Kind: instance method of Shaku
Returns: Logger - Logger instance.
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();
Kind: global class
BooleanAnimatorAnimatorAnimatorAnimatorAnimatorAnimatorAnimatorAnimatorAnimatorCreate the animator.
| Param | Type | Description |
|---|---|---|
| target | \* |
Any object you want to animate. |
Speed factor to multiply with delta every time this animator updates.
Kind: instance property of Animator
BooleanGet if this animator finished.
Kind: instance property of Animator
Returns: Boolean - True if animator finished.
Update this animator with a given delta time.
Kind: instance method of Animator
| Param | Type | Description |
|---|---|---|
| delta | Number |
Delta time to progress this animator by. |
AnimatorSet a method to run when animation ends.
Kind: instance method of Animator
Returns: Animator - this.
| Param | Type | Description |
|---|---|---|
| callback | function |
Callback to invoke when done. |
AnimatorSet smooth damp. If true, lerping will go slower as the animation reach its ending.
Kind: instance method of Animator
Returns: Animator - this.
| Param | Type | Description |
|---|---|---|
| enable | Boolean |
set smooth damp mode. |
AnimatorSet if the animator should repeat itself.
Kind: instance method of Animator
Returns: Animator - this.
| Param | Type | Description |
|---|---|---|
| enable | Boolean | Number |
false to disable repeating, true for endless repeats, or a number for limited number of repeats. |
| reverseAnimation | Boolean |
if true, it will reverse animation to repeat it instead of just “jumping” back to starting state. |
AnimatorIf true, will reverse animation back to start values after done.
This is equivalent to calling repeats(1, true).
Kind: instance method of Animator
Returns: Animator - this.
AnimatorSet ‘from’ values. You don’t have to provide ‘from’ values, when a value is not set the animator will just take whatever was set in target when first update is called.
Kind: instance method of Animator
Returns: Animator - this.
| Param | Type | Description |
|---|---|---|
| values | \* |
Values to set as ‘from’ values. Key = property name in target (can contain dots for nested), value = value to start animation from. |
AnimatorSet ‘to’ values, ie the result when animation ends.
Kind: instance method of Animator
Returns: Animator - this.
| Param | Type | Description |
|---|---|---|
| values | \* |
Values to set as ‘to’ values. Key = property name in target (can contain dots for nested), value = value to start animation from. |
Flip between the ‘from’ and the ‘to’ states.
Kind: instance method of Animator
AnimatorMake this Animator update automatically with the gameTime delta time. Note: this will change the speedFactor property.
Kind: instance method of Animator
Returns: Animator - this.
| Param | Type | Description |
|---|---|---|
| seconds | Number |
Animator duration time in seconds. |
AnimatorReset animator progress.
Kind: instance method of Animator
Returns: Animator - this.
AnimatorMake this Animator update automatically with the gameTime delta time, until its done.
Kind: instance method of Animator
Returns: Animator - this.
A 3D box shape.
Kind: global class
BoxBoxBoxBoxBoxBoxBoxBooleanVector3Vector3BoxBoxBoxBooleanBooleanBooleanBooleanBooleanVector3NumberBoxBoxBoxBooleanCreate the 3d box.
| Param | Type | Description |
|---|---|---|
| min | Vector3 |
Box min vector. |
| max | Vector3 |
Box max vector. |
BoxSet the box min and max corners.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| min | Vector3 |
Box min vector. |
| max | Vector3 |
Box max vector. |
BoxSet box values from array.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| array | Array.<Number> |
Array of values to load from. |
BoxSet box from array of points.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| points | Array.<Vector3> |
Points to set box from. |
BoxSet box from center and size.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| center | Vector3 |
Center position. |
| size | Vector3 |
Box size. |
BoxClone this box.
Kind: instance method of Box
Returns: Box - Cloned box.
BoxCopy values from another box.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to copy. |
BoxTurn this box into empty state.
Kind: instance method of Box
Returns: Box - Self.
BooleanCheck if this box is empty.
Kind: instance method of Box
Returns: Boolean - True if empty.
Vector3Get center position.
Kind: instance method of Box
Returns: Vector3 - Center position.
Vector3Get box size.
Kind: instance method of Box
Returns: Vector3 - Box size.
BoxExpand this box by a point. This will adjust the box boundaries to contain the point.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Point to extend box by. |
BoxExpand this box by pushing its boundaries by a vector. This will adjust the box boundaries by pushing them away from the center by the value of the given vector.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| vector | Vector3 |
Vector to expand by. |
BoxExpand this box by pushing its boundaries by a given scalar. This will adjust the box boundaries by pushing them away from the center by the value of the given scalar.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| scalar | Number |
Value to expand by. |
BooleanCheck if this box contains a point.
Kind: instance method of Box
Returns: Boolean - True if box containing the point.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Point to check. |
BooleanCheck if this box contains another box.
Kind: instance method of Box
Returns: Boolean - True if box containing the box.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to check. |
BooleanCheck if this box collides with another box.
Kind: instance method of Box
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to test collidion with. |
BooleanCheck if this box collides with a sphere.
Kind: instance method of Box
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| sphere | Sphere |
Sphere to test collidion with. |
BooleanCheck if this box collides with a plane.
Kind: instance method of Box
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| plane | Plane |
Plane to test collidion with. |
Vector3Clamp a given vector inside this box.
Kind: instance method of Box
Returns: Vector3 - Vector clammped.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Vector to clamp. |
NumberGet distance between this box and a given point.
Kind: instance method of Box
Returns: Number - Distance to point.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Point to get distance to. |
BoxComputes the intersection of this box with another box. This will set the upper bound of this box to the lesser of the two boxes’ upper bounds and the lower bound of this box to the greater of the two boxes’ lower bounds. If there’s no overlap, makes this box empty.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to intersect with. |
BoxComputes the union of this box and box. This will set the upper bound of this box to the greater of the two boxes’ upper bounds and the lower bound of this box to the lesser of the two boxes’ lower bounds.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to union with. |
BoxMove this box.
Kind: instance method of Box
Returns: Box - Self.
| Param | Type | Description |
|---|---|---|
| offset | Vector3 |
Offset to move box by. |
BooleanCheck if equal to another box.
Kind: instance method of Box
Returns: Boolean - True if boxes are equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| other | Box |
Other box to compare to. |
Implement a simple 2d Circle.
Kind: global class
CircleBooleanBoolean\*Create the Circle.
| Param | Type | Description |
|---|---|---|
| center | Vector2 |
Circle center position. |
| radius | Number |
Circle radius. |
CircleReturn a clone of this circle.
Kind: instance method of Circle
Returns: Circle - Cloned circle.
BooleanCheck if this circle contains a Vector2.
Kind: instance method of Circle
Returns: Boolean - if point is contained within the circle.
| Param | Type | Description |
|---|---|---|
| p | Vector2 |
Point to check. |
BooleanCheck if equal to another circle.
Kind: instance method of Circle
Returns: Boolean - True if circles are equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| other | Circle |
Other circle to compare to. |
\*Convert to dictionary.
Kind: instance method of Circle
Returns: \* - Dictionary with {center, radius}.
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
CircleCreate circle from a dictionary.
Kind: static method of Circle
Returns: Circle - Newly created circle.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {center, radius}. |
CircleLerp between two circle.
Kind: static method of Circle
Returns: Circle - result circle.
| Param | Type | Description |
|---|---|---|
| p1 | Circle |
First circle. |
| p2 | Circle |
Second circle. |
| a | Number |
Lerp factor (0.0 - 1.0). |
Implement a color. All color components are expected to be in 0.0 - 1.0 range (and not 0-255).
Kind: global class
NumberNumberNumberNumberNumberNumberNumberNumberStringNumberNumberColorColorColor\*NumberArray.<String>StringColorColorColorColorColorColorCreate the color.
| Param | Type | Description |
|---|---|---|
| r | Number |
Color red component (value range: 0-1). |
| g | Number |
Color green component (value range: 0-1). |
| b | Number |
Color blue component (value range: 0-1). |
| [a] | Number |
Color alpha component (value range: 0-1). |
NumberGet r component.
Kind: instance property of Color
Returns: Number - Red component.
NumberGet g component.
Kind: instance property of Color
Returns: Number - Green component.
NumberGet b component.
Kind: instance property of Color
Returns: Number - Blue component.
NumberGet a component.
Kind: instance property of Color
Returns: Number - Alpha component.
NumberSet r component.
Kind: instance property of Color
Returns: Number - Red component after change.
NumberSet g component.
Kind: instance property of Color
Returns: Number - Green component after change.
NumberSet b component.
Kind: instance property of Color
Returns: Number - Blue component after change.
NumberSet a component.
Kind: instance property of Color
Returns: Number - Alpha component after change.
StringConvert this color to hex string (starting with ‘#’).
Kind: instance property of Color
Returns: String - Color as hex.
NumberConvert this color to decimal number.
Kind: instance property of Color
Returns: Number - Color as decimal RGBA.
NumberConvert this color to decimal number.
Kind: instance property of Color
Returns: Number - Color as decimal ARGB.
Convert this color to a float array.
Kind: instance property of Color
Get if this color is pure black (ignoring alpha).
Kind: instance property of Color
Get if this color is transparent black.
Kind: instance property of Color
ColorSet the color components.
Kind: instance method of Color
Returns: Color - this.
| Param | Type | Description |
|---|---|---|
| r | Number |
Color red component (value range: 0-1). |
| g | Number |
Color green component (value range: 0-1). |
| b | Number |
Color blue component (value range: 0-1). |
| a | Number |
Color alpha component (value range: 0-1). |
ColorSet the color components from byte values (0-255).
Kind: instance method of Color
Returns: Color - this.
| Param | Type | Description |
|---|---|---|
| r | Number |
Color red component (value range: 0-255). |
| g | Number |
Color green component (value range: 0-255). |
| b | Number |
Color blue component (value range: 0-255). |
| a | Number |
Color alpha component (value range: 0-255). |
ColorCopy all component values from another color.
Kind: instance method of Color
Returns: Color - this.
| Param | Type | Description |
|---|---|---|
| other | Color |
Color to copy values from. |
\*Convert to dictionary.
Kind: instance method of Color
Returns: \* - Dictionary with {r,g,b,a}
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 1. You can use fromDict on minimized dicts. |
NumberReturn a clone of this color.
Kind: instance method of Color
Returns: Number - Cloned color.
Convert to string.
Kind: instance method of Color
Check if equal to another color.
Kind: instance method of Color
| Param | Type | Description |
|---|---|---|
| other | Color |
Other color to compare to. |
Array.<String>Get array with all built-in web color names.
Kind: static property of Color
Returns: Array.<String> - Array with color names.
StringConvert a single component to hex value.
Kind: static method of Color
Returns: String - Component as hex value.
| Param | Type | Description |
|---|---|---|
| c | Number |
Value to convert to hex. |
ColorCreate color from hex value.
Kind: static method of Color
Returns: Color - New color value.
| Param | Type | Description |
|---|---|---|
| val | String |
Number value (hex), as #rrggbbaa. |
ColorCreate color from decimal value.
Kind: static method of Color
Returns: Color - New color value.
| Param | Type | Description |
|---|---|---|
| val | Number |
Number value (int). |
| includeAlpha | Number |
If true, will include alpha value. |
ColorCreate color from a dictionary.
Kind: static method of Color
Returns: Color - Newly created color.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {r,g,b,a}. |
ColorReturn a random color.
Kind: static method of Color
Returns: Color - Randomized color.
| Param | Type | Description |
|---|---|---|
| includeAlpha | Boolean |
If true, will also randomize alpha. |
ColorBuild and return new color from bytes array.
Kind: static method of Color
Returns: Color - Newly created color.
| Param | Type | Description |
|---|---|---|
| bytes | Array.<Number> |
Bytes array to build color from. |
| [offset] | Number |
Optional offset to read bytes from. |
ColorLerp between two colors.
Kind: static method of Color
Returns: Color - result color.
| Param | Type | Description |
|---|---|---|
| p1 | Color |
First color. |
| p2 | Color |
Second color. |
| a | Number |
Lerp factor (0.0 - 1.0). |
Implement a 3D Frustum shape.
Kind: global class
Create the frustum.
| Param | Type | Description |
|---|---|---|
| p0 | Plane |
Frustum plane. |
| p1 | Plane |
Frustum plane. |
| p2 | Plane |
Frustum plane. |
| p3 | Plane |
Frustum plane. |
| p4 | Plane |
Frustum plane. |
| p5 | Plane |
Frustum plane. |
FrustumSet the Frustum values.
Kind: instance method of Frustum
Returns: Frustum - Self.
| Param | Type | Description |
|---|---|---|
| p0 | Plane |
Frustum plane. |
| p1 | Plane |
Frustum plane. |
| p2 | Plane |
Frustum plane. |
| p3 | Plane |
Frustum plane. |
| p4 | Plane |
Frustum plane. |
| p5 | Plane |
Frustum plane. |
FrustumCopy values from another frustum.
Kind: instance method of Frustum
Returns: Frustum - Self.
| Param | Type | Description |
|---|---|---|
| frustum | Frustum |
Frustum to copy. |
FrustumSet frustum from projection matrix.
Kind: instance method of Frustum
Returns: Frustum - Self.
| Param | Type | Description |
|---|---|---|
| m | Matrix |
Matrix to build frustum from. |
BooleanCheck if the frustum collides with a sphere.
Kind: instance method of Frustum
Returns: Boolean - True if point is in frustum, false otherwise.
| Param | Type | Description |
|---|---|---|
| sphere | Sphere |
Sphere to check. |
BooleanCheck if collide with a box.
Kind: instance method of Frustum
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to check. |
BooleanCheck if the frustum contains a point.
Kind: instance method of Frustum
Returns: Boolean - True if point is in frustum, false otherwise.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Vector to check. |
FrustumClone this frustum.
Kind: instance method of Frustum
Returns: Frustum - Cloned frustum.
Class to hold current game time, both elapse and delta from last frame.
Kind: global class
Numbercreate the gametime object with current time.
Current timestamp
Kind: instance property of GameTime
Delta time struct. Contains: milliseconds, seconds.
Kind: instance property of GameTime
Elapsed time struct. Contains: milliseconds, seconds.
Kind: instance property of GameTime
Delta time, in seconds, since last frame.
Kind: instance property of GameTime
Total time, in seconds, since Shaku was initialized.
Kind: instance property of GameTime
Raw timestamp in milliseconds. This value updates only as long as you run Shaku frames, and continue to update even if game is paused.
Kind: instance property of GameTime
NumberGet raw timestamp in milliseconds. This value updates only as long as you run Shaku frames, and continue to update even if game is paused.
Kind: static method of GameTime
Returns: Number - raw timestamp in milliseconds.
Reset elapsed and delta time.
Kind: static method of GameTime
Reset current frame’s delta time.
Kind: static method of GameTime
Utility class to arrange rectangles in minimal region.
\*Efficiently arrange rectangles into a minimal size area. Based on code from here: https://github.com/mapbox/potpack
Kind: static method of ItemsSorter
Returns: \* - Result object with the following keys: {width, height, rectangles, utilized}.
width = required container width.
height = required container width.
rectangles = list of sorted rectangles. every entry has {x, y, width, height, source} where x and y are the offset in container and source is the source input object.
utilized = how much of the output space was utilized.
| Param | Type | Description |
|---|---|---|
| rectangles | Array.<(Rectangle\|Vector2\|\*)> |
Array of vectors or rectangles to sort. If the object have ‘width’ and ‘height’ properties, these properties will be used to define the rectangle size. If not but the object have ‘x’ and ‘y’ properties, x and y will be taken instead. The source object will be included in the result objects. |
| [processRegionWidthMethod] | function |
If provided, will run this method when trying to decide on the result region width. Method receive desired width as argument, and return a new width to override the decision. You can use this method to limit max width or round it to multiplies of 2 for textures. Note: by default, the algorithm will try to create a square region. |
| [extraMargins] | Vector2 |
Optional extra empty pixels to add between textures in atlas. |
Example
// 'id' will be used to identify the items after the sort.
let boxes = [{x: 100, y: 50, id: 1}, {x: 50, y: 70, id: 2}, {x: 125, y: 85, id: 3}, ... more boxes here ];
let result = RectanglesSorter.arrangeRectangles(boxes);
// show result
console.log(`Output region size is: ${result.width},${result.height}, and it utilizes ${result.utilized} of the area.`);
for (let res of result.rectangles) {
console.log(`Rectangle ${res.source.id} is at position: ${res.x},${res.y}.`);
}
Implement a simple 2d Line.
Kind: global class
Line\*BooleanBooleanNumberBooleanCreate the Line.
| Param | Type | Description |
|---|---|---|
| from | Vector2 |
Line start position. |
| to | Vector2 |
Line end position. |
LineReturn a clone of this line.
Kind: instance method of Line
Returns: Line - Cloned line.
\*Convert to dictionary.
Kind: instance method of Line
Returns: \* - Dictionary with {from, to}.
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
BooleanCheck if this circle contains a Vector2.
Kind: instance method of Line
Returns: Boolean - if point is contained within the circle.
| Param | Type | Description |
|---|---|---|
| p | Vector2 |
Point to check. |
| threshold | Number |
Distance between point and line to consider as intersecting. Default is 0.5, meaning it will treat point and line as round integers (sort-of). |
BooleanCheck if this line collides with another line.
Kind: instance method of Line
Returns: Boolean - True if lines collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| other | Line |
Other line to test collision with. |
NumberGet the shortest distance between this line segment and a vector.
Kind: instance method of Line
Returns: Number - Shortest distance between line and vector.
| Param | Type | Description |
|---|---|---|
| v | Vector2 |
Vector to get distance to. |
BooleanCheck if equal to another circle.
Kind: instance method of Line
Returns: Boolean - True if circles are equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| other | Circle |
Other circle to compare to. |
LineCreate Line from a dictionary.
Kind: static method of Line
Returns: Line - Newly created line.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {from, to}. |
LineLerp between two lines.
Kind: static method of Line
Returns: Line - result lines.
| Param | Type | Description |
|---|---|---|
| l1 | Line |
First lines. |
| l2 | Line |
Second lines. |
| a | Number |
Lerp factor (0.0 - 1.0). |
Implement some math utilities functions.
Kind: global class
NumberNumberNumberNumberNumberNumberNumberNumberNumberNumberNumberNumberNumberVector3NumberPerform linear interpolation between start and end values.
Kind: static method of MathHelper
Returns: Number - interpolated value between start and end.
| Param | Type | Description |
|---|---|---|
| start | Number |
Starting value. |
| end | Number |
Ending value. |
| amount | Number |
How much to interpolate from start to end. |
NumberCalculate 2d dot product.
Kind: static method of MathHelper
Returns: Number - dot product result.
| Param | Type | Description |
|---|---|---|
| x1 | Number |
First vector x. |
| y1 | Number |
First vector y. |
| x2 | Number |
Second vector x. |
| y2 | Number |
Second vector y. |
NumberMake a number a multiply of another number by rounding it up.
Kind: static method of MathHelper
Returns: Number - Result number.
| Param | Type | Description |
|---|---|---|
| numToRound | Number |
Number to round up. |
| multiple | Number |
Number to make ‘numToRound’ a multiply of. |
NumberConvert degrees to radians.
Kind: static method of MathHelper
Returns: Number - Value as radians.
| Param | Type | Description |
|---|---|---|
| degrees | Number |
Degrees value to convert to radians. |
NumberConvert radians to degrees.
Kind: static method of MathHelper
Returns: Number - Value as degrees.
| Param | Type | Description |
|---|---|---|
| radians | Number |
Radians value to convert to degrees. |
NumberFind shortest distance between two radians, with sign (ie distance can be negative).
Kind: static method of MathHelper
Returns: Number - Shortest distance between radians.
| Param | Type | Description |
|---|---|---|
| a1 | Number |
First radian. |
| a2 | Number |
Second radian. |
NumberFind shortest distance between two radians.
Kind: static method of MathHelper
Returns: Number - Shortest distance between radians.
| Param | Type | Description |
|---|---|---|
| a1 | Number |
First radian. |
| a2 | Number |
Second radian. |
NumberFind shortest distance between two angles in degrees, with sign (ie distance can be negative).
Kind: static method of MathHelper
Returns: Number - Shortest distance between angles.
| Param | Type | Description |
|---|---|---|
| a1 | Number |
First angle. |
| a2 | Number |
Second angle. |
NumberFind shortest distance between two angles in degrees.
Kind: static method of MathHelper
Returns: Number - Shortest distance between angles.
| Param | Type | Description |
|---|---|---|
| a1 | Number |
First angle. |
| a2 | Number |
Second angle. |
NumberPerform linear interpolation between radian values. Unlike the regular lerp method, this method will take wrapping into consideration, and will always lerp via the shortest distance.
Kind: static method of MathHelper
Returns: Number - interpolated radians between start and end.
| Param | Type | Description |
|---|---|---|
| a1 | Number |
Starting value. |
| a2 | Number |
Ending value. |
| alpha | Number |
How much to interpolate from start to end. |
NumberPerform linear interpolation between degrees. Unlike the regular lerp method, this method will take wrapping into consideration, and will always lerp via the shortest distance.
Kind: static method of MathHelper
Returns: Number - interpolated degrees between start and end.
| Param | Type | Description |
|---|---|---|
| a1 | Number |
Starting value. |
| a2 | Number |
Ending value. |
| alpha | Number |
How much to interpolate from start to end. |
NumberRound numbers from 10’th digit. This is useful for calculations that should return round or almost round numbers, but have a long tail of 0’s and 1 due to floating points accuracy.
Kind: static method of MathHelper
Returns: Number - Rounded number.
| Param | Type | Description |
|---|---|---|
| num | Number |
Number to round. |
NumberWrap degrees value to be between 0 to 360.
Kind: static method of MathHelper
Returns: Number - degrees wrapped to be 0-360 values.
| Param | Type | Description |
|---|---|---|
| degrees | Number |
Degrees to wrap. |
Vector3Calculate the normal vector of a polygon using 3 points on it.
Kind: static method of MathHelper
Returns: Vector3 - Normal vector, normalized.
| Param | Type | Description |
|---|---|---|
| v1 | Vector3 |
Vector on the polygon. |
| v2 | Vector3 |
Vector on the polygon. |
| v3 | Vector3 |
Vector on the polygon. |
Implements a matrix.
Kind: global class
MatrixMatrixMatrixMatrixMatrixMatrixMatrixMatrixMatrixMatrixMatrixMatrixVertexVector2Vector3Create the matrix.
| Param | Description |
|---|---|
| values | matrix values array. |
| cloneValues | if true or undefined, will clone values instead of just holding a reference to them. |
Set the matrix values.
Kind: instance method of Matrix
MatrixClone the matrix.
Kind: instance method of Matrix
Returns: Matrix - Cloned matrix.
BooleanCompare this matrix to another matrix.
Kind: instance method of Matrix
Returns: Boolean - If matrices are the same.
| Param | Type | Description |
|---|---|---|
| other | Matrix |
Matrix to compare to. |
MatrixClone and invert the matrix.
Kind: instance method of Matrix
Returns: Matrix - Clonsed inverted matrix.
MatrixInvert this matrix.
Kind: instance method of Matrix
Returns: Matrix - Self.
Vector2 | Vector3 | Vector3Transform a target.
Kind: instance method of Matrix
Returns: Vector2 | Vector3 | Vector3 - Transformed result.
| Param | Type | Description |
|---|---|---|
| target | Vector2 | Vector3 | Vertex |
Transforms a target, that can be vector2, vector3, or vertex. |
MatrixMultiply this matrix with another matrix, putting results in self.
Kind: instance method of Matrix
Returns: Matrix - This.
| Param | Type | Description |
|---|---|---|
| other | Matrix |
Matrix to multiply with. |
MatrixMultiply this matrix with another matrix and return a new result matrix.
Kind: instance method of Matrix
Returns: Matrix - New result matrix.
| Param | Type | Description |
|---|---|---|
| other | Matrix |
Matrix to multiply with. |
MatrixCreate an orthographic projection matrix.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreate a perspective projection matrix.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreate a translation matrix.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreate a scale matrix.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreate a rotation matrix around X axis.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreate a rotation matrix around Y axis.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreate a rotation matrix around Z axis.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixMultiply two matrices.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
MatrixCreates a look-at matrix - a matrix rotated to look at a given position.
Kind: static method of Matrix
Returns: Matrix - a new matrix with result.
| Param | Type | Description |
|---|---|---|
| eyePosition | Vector3 |
Eye position. |
| targetPosition | Vector3 |
Position the matrix should look at. |
| [upVector] | Vector3 |
Optional vector representing ‘up’ direction. |
MatrixMultiply an array of matrices.
Kind: static method of Matrix
Returns: Matrix - new matrix with multiply result.
| Param | Type | Description |
|---|---|---|
| matrices | Array.<Matrix> |
Matrices to multiply. |
MatrixMultiply two matrices and put result in first matrix.
Kind: static method of Matrix
Returns: Matrix - matrixA, after it was modified.
MatrixMultiply an array of matrices into the first matrix in the array.
Kind: static method of Matrix
Returns: Matrix - first matrix in array, after it was modified.
| Param | Type | Description |
|---|---|---|
| matrices | Array.<Matrix> |
Matrices to multiply. |
VertexTransform a 2d vertex.
Kind: static method of Matrix
Returns: Vertex - A transformed vertex (cloned, not the original).
| Param | Type | Description |
|---|---|---|
| matrix | Matrix |
Matrix to use to transform vector. |
| vertex | Vertex |
Vertex to transform. |
Vector2Transform a 2d vector.
Kind: static method of Matrix
Returns: Vector2 - Transformed vector.
| Param | Type | Description |
|---|---|---|
| matrix | Matrix |
Matrix to use to transform vector. |
| vector | Vector2 |
Vector to transform. |
Vector3Transform a 3d vector.
Kind: static method of Matrix
Returns: Vector3 - Transformed vector.
| Param | Type | Description |
|---|---|---|
| matrix | Matrix |
Matrix to use to transform vector. |
| vector | Vector3 |
Vector to transform. |
Interface for a supported grid.
Kind: global class
BooleanNumberBooleanCheck if a given tile is blocked from a given neihbor.
Kind: instance method of IGrid
Returns: Boolean - Can we travel from _from to _to?
| Param | Type | Description |
|---|---|---|
| _from | Vector2 | Vector3 |
Source tile index. |
| _to | Vector2 | Vector3 |
Target tile index. Must be a neighbor of _from. |
NumberGet the price to travel on a given tile. Should return 1 for “normal” traveling price, > 1 for expensive tile, and < 1 for a cheap tile to pass on.
Kind: instance method of IGrid
Returns: Number - Price factor to walk on.
| Param | Type | Description |
|---|---|---|
| _index | Vector2 | Vector3 |
Tile index. |
A path node.
Kind: global class
Create the node from a position.
| Param | Type | Description |
|---|---|---|
| position | Vector2 | Vector3 |
Node position. |
Get the node fCost factor.
Kind: instance property of Node
Generate 2d perlin noise. Based on code from noisejs by Stefan Gustavson. https://github.com/josephg/noisejs/blob/master/perlin.js
Kind: global class
Create the perlin noise generator.
| Param | Type | Description |
|---|---|---|
| seed | Number |
Seed for perlin noise, or undefined for random. |
Set the perlin noise seed.
Kind: instance method of Perlin
| Param | Type | Description |
|---|---|---|
| seed | Number |
New seed value. May be either a decimal between 0 to 1, or an unsigned short between 0 to 65536. |
NumberGenerate a perlin noise value for x,y coordinates.
Kind: instance method of Perlin
Returns: Number - Perlin noise value for given point.
| Param | Type | Description |
|---|---|---|
| x | Number |
X coordinate to generate perlin noise for. |
| y | Number |
Y coordinate to generate perlin noise for. |
| blurDistance | Number |
Distance to take neighbors to blur returned value with. Defaults to 0.25. |
| contrast | Number |
Optional contrast factor. |
NumberGenerate a perlin noise value for x,y coordinates.
Kind: instance method of Perlin
Returns: Number - Perlin noise value for given point, ranged from 0 to 1.
| Param | Type | Description |
|---|---|---|
| x | Number |
X coordinate to generate perlin noise for. |
| y | Number |
Y coordinate to generate perlin noise for. |
| contrast | Number |
Optional contrast factor. |
A plane in 3D space.
Kind: global class
PlanePlanePlanePlanePlanePlanePlaneNumberNumberBooleanBooleanVector3PlaneBooleanPlaneCreate the plane.
| Param | Type | Default | Description |
|---|---|---|---|
| normal | Vector3 |
Plane normal vector. | |
| constant | Number |
0 |
Plane constant. |
PlaneSet the plane components.
Kind: instance method of Plane
Returns: Plane - Self.
| Param | Type | Description |
|---|---|---|
| normal | Vector3 |
Plane normal. |
| constant | Number |
Plane constant. |
PlaneSet the plane components.
Kind: instance method of Plane
Returns: Plane - Self.
| Param | Type | Description |
|---|---|---|
| x | Number |
Plane normal X. |
| y | Number |
Plane normal Y. |
| z | Number |
Plane normal Z. |
| w | Number |
Plane constant. |
PlaneSet plane from normal and coplanar point vectors.
Kind: instance method of Plane
Returns: Plane - Self.
| Param | Type | Description |
|---|---|---|
| normal | Vector3 |
Plane normal. |
| point | Vector3 |
Coplanar point. |
PlaneCopy values from another plane.
Kind: instance method of Plane
Returns: Plane - Self.
| Param | Type | Description |
|---|---|---|
| plane | Plane |
Plane to copy. |
PlaneNormalize the plane.
Kind: instance method of Plane
Returns: Plane - self.
PlaneNormalize a clone of this plane.
Kind: instance method of Plane
Returns: Plane - Normalized clone.
PlaneNegate this plane.
Kind: instance method of Plane
Returns: Plane - Self.
NumberCalculate distance to point.
Kind: instance method of Plane
Returns: Number - Distance to point.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Point to calculate distance to. |
NumberCalculate distance to sphere.
Kind: instance method of Plane
Returns: Number - Distance to sphere.
| Param | Type | Description |
|---|---|---|
| sphere | Sphere |
Sphere to calculate distance to. |
BooleanCheck if this plane collide with a line.
Kind: instance method of Plane
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| line | Line |
Line to check. |
BooleanCheck if this plane collide with a sphere.
Kind: instance method of Plane
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| sphere | Sphere |
Sphere to check. |
Vector3Coplanar a point.
Kind: instance method of Plane
Returns: Vector3 - Coplanar point as a new vector.
PlaneTranslate this plane.
Kind: instance method of Plane
Returns: Plane - Self.
| Param | Type | Description |
|---|---|---|
| offset | Vector3 |
Offset to translate to. |
BooleanCheck if this plane equals another plane.
Kind: instance method of Plane
Returns: Boolean - True if equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| plane | Plane |
Other plane to compare to. |
PlaneClone this plane.
Kind: instance method of Plane
Returns: Plane - Cloned plane.
A 3D ray.
Kind: global class
PlaneRayBooleanVector3NumberNumberBooleanBooleanVector3 | nullRayCreate the Ray.
| Param | Type | Description |
|---|---|---|
| origin | Vector3 |
Ray origin point. |
| direction | Vector3 |
Ray 3d direction. |
PlaneSet the ray components.
Kind: instance method of Ray
Returns: Plane - Self.
| Param | Type | Description |
|---|---|---|
| origin | Vector3 |
Ray origin point. |
| direction | Vector3 |
Ray 3d direction. |
RayCopy values from another ray.
Kind: instance method of Ray
Returns: Ray - Self.
| Param | Type | Description |
|---|---|---|
| ray | Ray |
Ray to copy. |
BooleanCheck if this ray equals another ray.
Kind: instance method of Ray
Returns: Boolean - True if equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| ray | Ray |
Other ray to compare to. |
Vector3Get the 3d point on the ray by distance from origin.
Kind: instance method of Ray
Returns: Vector3 - Point on ray from origin.
| Param | Type | Description |
|---|---|---|
| distance | Number |
Distance from origin to travel. |
NumberCalculate distance to a 3d point.
Kind: instance method of Ray
Returns: Number - Distance to point.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Point to calculate distance to. |
NumberCalculate squared distance to a 3d point.
Kind: instance method of Ray
Returns: Number - Squared distance to point.
| Param | Type | Description |
|---|---|---|
| point | Vector3 |
Point to calculate distance to. |
BooleanCheck if this ray collides with a sphere.
Kind: instance method of Ray
Returns: Boolean - True if collide with sphere, false otherwise.
| Param | Type | Description |
|---|---|---|
| sphere | Sphere |
Sphere to test collision with. |
BooleanCheck if this ray collides with a box.
Kind: instance method of Ray
Returns: Boolean - True if collide with box, false otherwise.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to test collision with. |
Vector3 | nullReturn the collision point between the ray and a box, or null if they don’t collide.
Kind: instance method of Ray
Returns: Vector3 | null - Collision point or null.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to get collision with. |
RayClone this ray.
Kind: instance method of Ray
Returns: Ray - Cloned ray.
Implement a simple 2d Rectangle.
Kind: global class
NumberNumberNumberNumberRectangleRectangleVector2Vector2Vector2RectangleVector2Vector2Vector2Vector2BooleanBooleanBooleanBooleanCircleRectangle\*Create the Rect.
| Param | Type | Description |
|---|---|---|
| x | Number |
Rect position X (top left corner). |
| y | Number |
Rect position Y (top left corner). |
| width | Number |
Rect width. |
| height | Number |
Rect height. |
NumberGet left value.
Kind: instance property of Rectangle
Returns: Number - rectangle left.
NumberGet right value.
Kind: instance property of Rectangle
Returns: Number - rectangle right.
NumberGet top value.
Kind: instance property of Rectangle
Returns: Number - rectangle top.
NumberGet bottom value.
Kind: instance property of Rectangle
Returns: Number - rectangle bottom.
RectangleSet rectangle values.
Kind: instance method of Rectangle
Returns: Rectangle - this.
| Param | Type | Description |
|---|---|---|
| x | Number |
Rectangle x position. |
| y | Number |
Rectangle y position. |
| width | Number |
Rectangle width. |
| height | Number |
Rectangle height. |
RectangleCopy another rectangle.
Kind: instance method of Rectangle
Returns: Rectangle - this.
| Param | Type | Description |
|---|---|---|
| other | other |
Rectangle to copy. |
Vector2Get position as Vector2.
Kind: instance method of Rectangle
Returns: Vector2 - Position vector.
Vector2Get size as Vector2.
Kind: instance method of Rectangle
Returns: Vector2 - Size vector.
Vector2Get center position.
Kind: instance method of Rectangle
Returns: Vector2 - Position vector.
RectangleReturn a clone of this rectangle.
Kind: instance method of Rectangle
Returns: Rectangle - Cloned rectangle.
Vector2Get top-left corner.
Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.
Vector2Get top-right corner.
Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.
Vector2Get bottom-left corner.
Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.
Vector2Get bottom-right corner.
Kind: instance method of Rectangle
Returns: Vector2 - Corner position vector.
Convert to string.
Kind: instance method of Rectangle
BooleanCheck if this rectangle contains a Vector2.
Kind: instance method of Rectangle
Returns: Boolean - if point is contained within the rectangle.
| Param | Type | Description |
|---|---|---|
| p | Vector2 |
Point to check. |
BooleanCheck if this rectangle collides with another rectangle.
Kind: instance method of Rectangle
Returns: Boolean - if rectangles collide.
| Param | Type | Description |
|---|---|---|
| other | Rectangle |
Rectangle to check collision with. |
BooleanCheck if this rectangle collides with a line.
Kind: instance method of Rectangle
Returns: Boolean - if rectangle collides with line.
| Param | Type | Description |
|---|---|---|
| line | Line |
Line to check collision with. |
BooleanChecks if this rectangle collides with a circle.
Kind: instance method of Rectangle
Returns: Boolean - if rectangle collides with circle.
| Param | Type | Description |
|---|---|---|
| circle | Circle |
Circle to check collision with. |
CircleGet the smallest circle containing this rectangle.
Kind: instance method of Rectangle
Returns: Circle - Bounding circle.
RectangleReturn a resized rectangle with the same center point.
Kind: instance method of Rectangle
Returns: Rectangle - resized rectangle.
| Param | Type | Description |
|---|---|---|
| amount | Number | Vector2 |
Amount to resize. |
Check if equal to another rectangle.
Kind: instance method of Rectangle
| Param | Type | Description |
|---|---|---|
| other | Rectangle |
Other rectangle to compare to. |
\*Convert to dictionary.
Kind: instance method of Rectangle
Returns: \* - Dictionary with {x,y,width,height}
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
RectangleBuild and return a rectangle from points.
Kind: static method of Rectangle
Returns: Rectangle - new rectangle from points.
| Param | Type | Description |
|---|---|---|
| points | Array.<Vector2> |
Points to build rectangle from. |
RectangleLerp between two rectangles.
Kind: static method of Rectangle
Returns: Rectangle - result rectangle.
| Param | Type | Description |
|---|---|---|
| p1 | Rectangle |
First rectangles. |
| p2 | Rectangle |
Second rectangles. |
| a | Number |
Lerp factor (0.0 - 1.0). |
RectangleCreate rectangle from a dictionary.
Kind: static method of Rectangle
Returns: Rectangle - Newly created rectangle.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {x,y,width,height}. |
Class to generate random numbers with seed.
Kind: global class
Number\*Create the seeded random object.
| Param | Type | Description |
|---|---|---|
| seed | Number |
Seed to start from. If not provided, will use 0. |
NumberGet next random value.
Kind: instance method of SeededRandom
Returns: Number - A randomly generated value.
| Param | Type | Description |
|---|---|---|
| min | Number |
Optional min value. If max is not provided, this will be used as max. |
| max | Number |
Optional max value. |
\*Pick a random value from array.
Kind: instance method of SeededRandom
Returns: \* - Random value from options array.
| Param | Type | Description |
|---|---|---|
| options | Array |
Options to pick random value from. |
A 3D sphere.
Kind: global class
SphereBooleanBoolean\*BooleanBooleanCreate the Sphere.
| Param | Type | Description |
|---|---|---|
| center | Vector3 |
Sphere center position. |
| radius | Number |
Sphere radius. |
SphereReturn a clone of this sphere.
Kind: instance method of Sphere
Returns: Sphere - Cloned sphere.
BooleanCheck if this sphere contains a Vector3.
Kind: instance method of Sphere
Returns: Boolean - if point is contained within the sphere.
| Param | Type | Description |
|---|---|---|
| p | Vector3 |
Point to check. |
BooleanCheck if equal to another sphere.
Kind: instance method of Sphere
Returns: Boolean - True if spheres are equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| other | Sphere |
Other sphere to compare to. |
\*Convert to dictionary.
Kind: instance method of Sphere
Returns: \* - Dictionary with {center, radius}.
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
BooleanCheck if collide with a box.
Kind: instance method of Sphere
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| box | Box |
Box to check. |
BooleanCheck if collide with a plane.
Kind: instance method of Sphere
Returns: Boolean - True if collide, false otherwise.
| Param | Type | Description |
|---|---|---|
| plane | Plane |
Plane to test. |
SphereCreate sphere from a dictionary.
Kind: static method of Sphere
Returns: Sphere - Newly created sphere.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {center, radius}. |
SphereLerp between two sphere.
Kind: static method of Sphere
Returns: Sphere - result sphere.
| Param | Type | Description |
|---|---|---|
| p1 | Sphere |
First sphere. |
| p2 | Sphere |
Second sphere. |
| a | Number |
Lerp factor (0.0 - 1.0). |
A thin wrapper layer around storage utility.
Kind: global class
BooleanBooleanBooleanString\*Create the storage.
| Param | Type | Description |
|---|---|---|
| adapters | Array.<StorageAdapter> |
List of storage adapters to pick from. Will use the first option returning ‘isValid()’ = true. |
| prefix | String |
Optional prefix to add to all keys under this storage instance. |
| valuesAsBase64 | Boolean |
If true, will encode and decode data as base64. |
| keysAsBase64 | Boolean |
If true, will encode and decode keys as base64. |
BooleanReturn if this storage adapter is persistent storage or not.
Kind: instance property of Storage
Returns: Boolean - True if this storage type is persistent.
BooleanCheck if this storage instance has a valid adapter.
Kind: instance property of Storage
Returns: Boolean - True if found a valid adapter to use, false otherwise.
BooleanCheck if a key exists.
Kind: instance method of Storage
Returns: Boolean - True if key exists in storage.
| Param | Type | Description |
|---|---|---|
| key | String |
Key to check. |
Set value.
Kind: instance method of Storage
| Param | Type | Description |
|---|---|---|
| key | String |
Key to set. |
| value | String |
Value to set. |
StringGet value.
Kind: instance method of Storage
Returns: String - Value or null if not set.
| Param | Type | Description |
|---|---|---|
| key | String |
Key to get. |
\*Get value and JSON parse it.
Kind: instance method of Storage
Returns: \* - Value as a dictionary object or null if not set.
| Param | Type | Description |
|---|---|---|
| key | String |
Key to get. |
Set value as JSON.
Kind: instance method of Storage
| Param | Type | Description |
|---|---|---|
| key | String |
Key to set. |
| value | \* |
Value to set as a dictionary. |
Delete value.
Kind: instance method of Storage
| Param | Type | Description |
|---|---|---|
| key | String |
Key to delete. |
Clear all values from this storage instance, based on prefix + adapter type.
Kind: instance method of Storage
Storage adapter class that implement access to a storage device. Used by the Storage utilitiy.
Kind: global class
BooleanBooleanBooleanStringBooleanReturn if this storage adapter is persistent storage or not.
Kind: instance property of StorageAdapter
Returns: Boolean - True if this storage type is persistent.
BooleanCheck if this adapter is OK to be used. For example, an adapter for localStorage will make sure it exists and not null.
Kind: instance method of StorageAdapter
Returns: Boolean - True if storage adapter is valid to be used.
BooleanCheck if a key exists.
Kind: instance method of StorageAdapter
Returns: Boolean - True if key exists in storage.
| Param | Type | Description |
|---|---|---|
| key | String |
Key to check. |
Set value.
Kind: instance method of StorageAdapter
| Param | Type | Description |
|---|---|---|
| key | String |
Key to set. |
| value | String |
Value to set. |
StringGet value.
Kind: instance method of StorageAdapter
Returns: String - Value or null if not set.
| Param | Type | Description |
|---|---|---|
| key | String |
Key to get. |
Delete value.
Kind: instance method of StorageAdapter
| Param | Type | Description |
|---|---|---|
| key | String |
Key to delete. |
Clear all values from this storage device.
Kind: instance method of StorageAdapter
| Param | Type | Description |
|---|---|---|
| prefix | String |
Storage keys prefix. |
Implement simple memory storage adapter.
Kind: global class
Create the memory storage adapter.
Kind: instance property of StorageAdapterMemory
Kind: instance method of StorageAdapterMemory
Kind: instance method of StorageAdapterMemory
Kind: instance method of StorageAdapterMemory
Kind: instance method of StorageAdapterMemory
Kind: instance method of StorageAdapterMemory
Kind: instance method of StorageAdapterMemory
Implement simple localstorage storage adapter.
Kind: global class
Kind: instance property of StorageAdapterLocalStorage
Kind: instance method of StorageAdapterLocalStorage
Kind: instance method of StorageAdapterLocalStorage
Kind: instance method of StorageAdapterLocalStorage
Kind: instance method of StorageAdapterLocalStorage
Kind: instance method of StorageAdapterLocalStorage
Kind: instance method of StorageAdapterLocalStorage
Implement simple sessionStorage storage adapter.
Kind: global class
Kind: instance property of StorageAdapterSessionStorage
Kind: instance method of StorageAdapterSessionStorage
Kind: instance method of StorageAdapterSessionStorage
Kind: instance method of StorageAdapterSessionStorage
Kind: instance method of StorageAdapterSessionStorage
Kind: instance method of StorageAdapterSessionStorage
Kind: instance method of StorageAdapterSessionStorage
Transformations helper class to store 2d position, rotation and scale. Can also perform transformations inheritance, where we combine local with parent transformations.
Kind: global class
functionVector2TransformModesTransformationTransformationTransformationTransformationTransformationVector2TransformModesTransformationTransformationTransformationTransformationTransformationNumberNumberNumberTransformModesTransformationTransformationTransformationTransformationTransformationBooleanTransformationMatrixCreate the transformations.
| Param | Type | Description |
|---|---|---|
| position | Vector2 |
Optional position value. |
| rotation | Number |
Optional rotation value. |
| scale | Vector2 |
Optional sscale value. |
Example
// create local and world transformations
const transform = new Shaku.utils.Transformation();
const worldTransform = new Shaku.utils.Transformation();
// set offset to world transofm and rotation to local transform
worldTransform.setPosition({x: 100, y:50});
transform.setRotation(5);
// combine transformations and convert to a matrix
const combined = Shaku.utils.Transformation.combine(transform, worldTransform);
const matrix = combined.asMatrix();
functionMethod to call when this transformation change. Function params: transformation instance (this), properties changed (boolean), transform modes changed (boolean).
Kind: instance property of Transformation
Vector2Get position.
Kind: instance method of Transformation
Returns: Vector2 - Position.
TransformModesGet position transformations mode.
Kind: instance method of Transformation
Returns: TransformModes - Position transformation mode.
TransformationSet position.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Vector2 |
New position. |
TransformationSet position X value.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
New position.x value. |
TransformationSet position Y value.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
New position.y value. |
TransformationMove position by a given vector.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Vector2 |
Vector to move position by. |
TransformationSet position transformations mode.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | TransformModes |
Position transformation mode. |
Vector2Get scale.
Kind: instance method of Transformation
Returns: Vector2 - Scale.
TransformModesGet scale transformations mode.
Kind: instance method of Transformation
Returns: TransformModes - Scale transformation mode.
TransformationSet scale.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Vector2 |
New scale. |
TransformationSet scale X value.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
New scale.x value. |
TransformationSet scale Y value.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
New scale.y value. |
TransformationScale by a given vector.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Vector2 |
Vector to scale by. |
TransformationSet scale transformations mode.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | TransformModes |
Scale transformation mode. |
NumberGet rotation.
Kind: instance method of Transformation
Returns: Number - rotation.
NumberGet rotation as degrees.
Kind: instance method of Transformation
Returns: Number - rotation.
NumberGet rotation as degrees, wrapped between 0 to 360.
Kind: instance method of Transformation
Returns: Number - rotation.
TransformModesGet rotation transformations mode.
Kind: instance method of Transformation
Returns: TransformModes - Rotation transformations mode.
TransformationSet rotation.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
New rotation. |
| wrap | Boolean |
If true, will wrap value if out of possible range. |
TransformationRotate transformation by given radians.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
Rotate value in radians. |
| wrap | Boolean |
If true, will wrap value if out of possible range. |
TransformationSet rotation as degrees.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
New rotation. |
| wrap | Boolean |
If true, will wrap value if out of possible range. |
TransformationRotate transformation by given degrees.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | Number |
Rotate value in degrees. |
TransformationSet rotation transformations mode.
Kind: instance method of Transformation
Returns: Transformation - this.
| Param | Type | Description |
|---|---|---|
| value | TransformModes |
Rotation transformation mode. |
BooleanCheck if this transformation equals another.
Kind: instance method of Transformation
Returns: Boolean - True if equal, false otherwise.
| Param | Type | Description |
|---|---|---|
| other | Transformation |
Other transform to compare to. |
TransformationReturn a clone of this transformations.
Kind: instance method of Transformation
Returns: Transformation - Cloned transformations.
Serialize this transformation into a dictionary.
Kind: instance method of Transformation
Deserialize this transformation from a dictionary.
Kind: instance method of Transformation
| Param | Type | Description |
|---|---|---|
| data | \* |
Data to set. |
MatrixCreate and return a transformation matrix.
Kind: instance method of Transformation
Returns: Matrix - New transformation matrix.
TransformationCombine child transformations with parent transformations.
Kind: static method of Transformation
Returns: Transformation - Combined transformations.
| Param | Type | Description |
|---|---|---|
| child | Transformation |
Child transformations. |
| parent | Transformation |
Parent transformations. |
A simple Vector object for 2d positions.
Kind: global class
Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2BooleanBooleanNumberVector2NumberNumberNumberNumberNumberNumberVector2Vector2NumberNumberNumberArray.<Number>\*Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2Vector2NumberNumberNumberNumberNumberNumberNumberVector2Vector2Vector2Create the Vector object.
| Param | Type | Default | Description |
|---|---|---|---|
| x | number |
0 |
Vector X. |
| y | number |
0 |
Vector Y. |
Vector2Clone the vector.
Kind: instance method of Vector2
Returns: Vector2 - cloned vector.
Vector2Set vector value.
Kind: instance method of Vector2
Returns: Vector2 - this.
| Param | Type | Description |
|---|---|---|
| x | Number |
X component. |
| y | Number |
Y component. |
Vector2Copy values from other vector into self.
Kind: instance method of Vector2
Returns: Vector2 - this.
Vector2Return a new vector of this + other.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector3 or number to add to all components. |
Vector2Return a new vector of this - other.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector3 or number to sub from all components. |
Vector2Return a new vector of this / other.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector3 or number to divide by all components. |
Vector2Return a new vector of this * other.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector2 or number to multiply with all components. |
Vector2Return a round copy of this vector.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
Vector2Return a floored copy of this vector.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
Vector2Return a ceiled copy of this vector.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
Vector2Set self values to be min values between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2 - Self.
| Param | Type | Description |
|---|---|---|
| v | Vector2 |
Vector to min with. |
Vector2Set self values to be max values between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2 - Self.
| Param | Type | Description |
|---|---|---|
| v | Vector2 |
Vector to max with. |
Vector2Create a clone vector that is the min result between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2 - Result vector.
| Param | Type | Description |
|---|---|---|
| v | Vector2 |
Vector to min with. |
Vector2Create a clone vector that is the max result between self and a given vector.
Kind: instance method of Vector2
Returns: Vector2 - Result vector.
| Param | Type | Description |
|---|---|---|
| v | Vector2 |
Vector to max with. |
Vector2Return a normalized copy of this vector.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
Vector2Get a copy of this vector rotated by radians.
Kind: instance method of Vector2
Returns: Vector2 - New vector with the length of this vector and direction rotated by given radians.
| Param | Type | Description |
|---|---|---|
| radians | Number |
Radians to rotate by. |
Vector2Get a copy of this vector rotated by degrees.
Kind: instance method of Vector2
Returns: Vector2 - New vector with the length of this vector and direction rotated by given degrees.
| Param | Type | Description |
|---|---|---|
| degrees | Number |
Degrees to rotate by. |
Vector2Add other vector values to self.
Kind: instance method of Vector2
Returns: Vector2 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector or number to add. |
Vector2Sub other vector values from self.
Kind: instance method of Vector2
Returns: Vector2 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector or number to substract. |
Vector2Divide this vector by other vector values.
Kind: instance method of Vector2
Returns: Vector2 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector or number to divide by. |
Vector2Multiply this vector by other vector values.
Kind: instance method of Vector2
Returns: Vector2 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector2 |
Vector or number to multiply by. |
Vector2Round self.
Kind: instance method of Vector2
Returns: Vector2 - this.
Vector2Floor self.
Kind: instance method of Vector2
Returns: Vector2 - this.
Vector2Ceil self.
Kind: instance method of Vector2
Returns: Vector2 - this.
Vector2Return a normalized copy of this vector.
Kind: instance method of Vector2
Returns: Vector2 - this.
BooleanReturn if vector equals another vector.
Kind: instance method of Vector2
Returns: Boolean - if vectors are equal.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector to compare to. |
BooleanReturn if vector approximately equals another vector.
Kind: instance method of Vector2
Returns: Boolean - if vectors are equal.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector to compare to. |
| threshold | Number |
Distance threshold to consider as equal. Defaults to 1. |
NumberReturn vector length (aka magnitude).
Kind: instance method of Vector2
Returns: Number - Vector length.
Vector2Return a copy of this vector multiplied by a factor.
Kind: instance method of Vector2
Returns: Vector2 - result vector.
NumberGet degrees between this vector and another vector.
Kind: instance method of Vector2
Returns: Number - Angle between vectors in degrees.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector. |
NumberGet radians between this vector and another vector.
Kind: instance method of Vector2
Returns: Number - Angle between vectors in radians.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector. |
NumberGet degrees between this vector and another vector. Return values between 0 to 360.
Kind: instance method of Vector2
Returns: Number - Angle between vectors in degrees.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector. |
NumberGet radians between this vector and another vector. Return values between 0 to PI2.
Kind: instance method of Vector2
Returns: Number - Angle between vectors in radians.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector. |
NumberCalculate distance between this vector and another vectors.
Kind: instance method of Vector2
Returns: Number - Distance between vectors.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector. |
NumberCalculate squared distance between this vector and another vector.
Kind: instance method of Vector2
Returns: Number - Distance between vectors.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Other vector. |
Vector2Return a clone and clamp its values to be between min and max.
Kind: instance method of Vector2
Returns: Vector2 - Clamped vector.
| Param | Type | Description |
|---|---|---|
| min | Vector2 |
Min vector. |
| max | Vector2 |
Max vector. |
Vector2Clamp this vector values to be between min and max.
Kind: instance method of Vector2
Returns: Vector2 - Self.
| Param | Type | Description |
|---|---|---|
| min | Vector2 |
Min vector. |
| max | Vector2 |
Max vector. |
NumberCalculate the dot product with another vector.
Kind: instance method of Vector2
Returns: Number - Dot product value.
| Param | Type | Description |
|---|---|---|
| other | Vector2 |
Vector to calculate dot with. |
NumberGet vector’s angle in degrees.
Kind: instance method of Vector2
Returns: Number - Vector angle in degrees.
NumberGet vector’s angle in radians.
Kind: instance method of Vector2
Returns: Number - Vector angle in degrees.
Convert to string.
Kind: instance method of Vector2
Array.<Number>Convert to array of numbers.
Kind: instance method of Vector2
Returns: Array.<Number> - Vector components as array.
\*Convert to dictionary.
Kind: instance method of Vector2
Returns: \* - Dictionary with {x,y}
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
Vector2Get vector (0,0).
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector with 1,1 values.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector with 0.5,0.5 values.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector with -1,0 values.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector with 1,0 values.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector with 0,-1 values.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector with 0,1 values.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get a random vector with length of 1.
Kind: static method of Vector2
Returns: Vector2 - result vector.
Vector2Get vector from degrees.
Kind: static method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| degrees | Number |
Angle to create vector from (0 = vector pointing right). |
Vector2Get vector from radians.
Kind: static method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| radians | Number |
Angle to create vector from (0 = vector pointing right). |
Vector2Lerp between two vectors.
Kind: static method of Vector2
Returns: Vector2 - result vector.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
| a | Number |
Lerp factor (0.0 - 1.0). |
NumberGet degrees between two vectors. Return values between -180 to 180.
Kind: static method of Vector2
Returns: Number - Angle between vectors in degrees.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
NumberGet radians between two vectors. Return values between -PI to PI.
Kind: static method of Vector2
Returns: Number - Angle between vectors in radians.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
NumberGet degrees between two vectors. Return values between 0 to 360.
Kind: static method of Vector2
Returns: Number - Angle between vectors in degrees.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
NumberGet radians between two vectors. Return values between 0 to PI2.
Kind: static method of Vector2
Returns: Number - Angle between vectors in radians.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
NumberCalculate distance between two vectors.
Kind: static method of Vector2
Returns: Number - Distance between vectors.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
NumberReturn cross product between two vectors.
Kind: static method of Vector2
Returns: Number - Cross between vectors.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
NumberReturn dot product between two vectors.
Kind: static method of Vector2
Returns: Number - Dot between vectors.
| Param | Type | Description |
|---|---|---|
| p1 | Vector2 |
First vector. |
| p2 | Vector2 |
Second vector. |
Vector2Parse and return a vector object from string in the form of “x,y”.
Kind: static method of Vector2
Returns: Vector2 - Parsed vector.
| Param | Type | Description |
|---|---|---|
| str | String |
String to parse. |
Vector2Create vector from array of numbers.
Kind: static method of Vector2
Returns: Vector2 - Vector instance.
| Param | Type | Description |
|---|---|---|
| arr | Array.<Number> |
Array of numbers to create vector from. |
Vector2Create vector from a dictionary.
Kind: static method of Vector2
Returns: Vector2 - Newly created vector.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {x,y}. |
A Vector object for 3d positions.
Kind: global class
Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3BooleanBooleanNumberVector3NumberNumberVector3Vector3NumberVector3Vector3Vector3Vector3Array.<Number>\*Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3Vector3NumberVector3Vector3Vector3Vector3Create the Vector object.
| Param | Type | Default | Description |
|---|---|---|---|
| x | number |
0 |
Vector X. |
| y | number |
0 |
Vector Y. |
| z | number |
0 |
Vector Z. |
Vector3Clone the vector.
Kind: instance method of Vector3
Returns: Vector3 - cloned vector.
Vector3Set vector value.
Kind: instance method of Vector3
Returns: Vector3 - this.
| Param | Type | Description |
|---|---|---|
| x | Number |
X component. |
| y | Number |
Y component. |
| z | Number |
Z component. |
Vector3Copy values from other vector into self.
Kind: instance method of Vector3
Returns: Vector3 - this.
Vector3Return a new vector of this + other.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector3 or number to add to all components. |
Vector3Return a new vector of this - other.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector3 or number to sub from all components. |
Vector3Return a new vector of this / other.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector3 or number to divide by all components. |
Vector3Return a new vector of this * other.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector3 or number to multiply with all components. |
Vector3Return a round copy of this vector.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
Vector3Return a floored copy of this vector.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
Vector3Return a ceiled copy of this vector.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
Vector3Return a normalized copy of this vector.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
Vector3Add other vector values to self.
Kind: instance method of Vector3
Returns: Vector3 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector or number to add. |
Vector3Sub other vector values from self.
Kind: instance method of Vector3
Returns: Vector3 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector or number to substract. |
Vector3Divide this vector by other vector values.
Kind: instance method of Vector3
Returns: Vector3 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector or number to divide by. |
Vector3Multiply this vector by other vector values.
Kind: instance method of Vector3
Returns: Vector3 - this.
| Param | Type | Description |
|---|---|---|
| Other | Number | Vector3 |
Vector or number to multiply by. |
Vector3Round self.
Kind: instance method of Vector3
Returns: Vector3 - this.
Vector3Floor self.
Kind: instance method of Vector3
Returns: Vector3 - this.
Vector3Ceil self.
Kind: instance method of Vector3
Returns: Vector3 - this.
Vector3Return a normalized copy of this vector.
Kind: instance method of Vector3
Returns: Vector3 - this.
BooleanReturn if vector equals another vector.
Kind: instance method of Vector3
Returns: Boolean - if vectors are equal.
| Param | Type | Description |
|---|---|---|
| other | Vector3 |
Other vector to compare to. |
BooleanReturn if vector approximately equals another vector.
Kind: instance method of Vector3
Returns: Boolean - if vectors are equal.
| Param | Type | Description |
|---|---|---|
| other | Vector3 |
Other vector to compare to. |
| threshold | Number |
Distance threshold to consider as equal. Defaults to 1. |
NumberReturn vector length (aka magnitude).
Kind: instance method of Vector3
Returns: Number - Vector length.
Vector3Return a copy of this vector multiplied by a factor.
Kind: instance method of Vector3
Returns: Vector3 - result vector.
NumberCalculate distance between this vector and another vector.
Kind: instance method of Vector3
Returns: Number - Distance between vectors.
| Param | Type | Description |
|---|---|---|
| other | Vector3 |
Other vector. |
NumberCalculate squared distance between this vector and another vector.
Kind: instance method of Vector3
Returns: Number - Distance between vectors.
| Param | Type | Description |
|---|---|---|
| other | Vector3 |
Other vector. |
Vector3Return a clone and clamp its values to be between min and max.
Kind: instance method of Vector3
Returns: Vector3 - Clamped vector.
| Param | Type | Description |
|---|---|---|
| min | Vector3 |
Min vector. |
| max | Vector3 |
Max vector. |
Vector3Clamp this vector values to be between min and max.
Kind: instance method of Vector3
Returns: Vector3 - Self.
| Param | Type | Description |
|---|---|---|
| min | Vector3 |
Min vector. |
| max | Vector3 |
Max vector. |
NumberCalculate the dot product with another vector.
Kind: instance method of Vector3
Returns: Number - Dot product value.
| Param | Type | Description |
|---|---|---|
| other | Vector3 |
Vector to calculate dot with. |
Vector3Set self values to be min values between self and a given vector.
Kind: instance method of Vector3
Returns: Vector3 - Self.
| Param | Type | Description |
|---|---|---|
| v | Vector3 |
Vector to min with. |
Vector3Set self values to be max values between self and a given vector.
Kind: instance method of Vector3
Returns: Vector3 - Self.
| Param | Type | Description |
|---|---|---|
| v | Vector3 |
Vector to max with. |
Vector3Create a clone vector that is the min result between self and a given vector.
Kind: instance method of Vector3
Returns: Vector3 - Result vector.
| Param | Type | Description |
|---|---|---|
| v | Vector3 |
Vector to min with. |
Vector3Create a clone vector that is the max result between self and a given vector.
Kind: instance method of Vector3
Returns: Vector3 - Result vector.
| Param | Type | Description |
|---|---|---|
| v | Vector3 |
Vector to max with. |
Convert to string.
Kind: instance method of Vector3
Array.<Number>Convert to array of numbers.
Kind: instance method of Vector3
Returns: Array.<Number> - Vector components as array.
\*Convert to dictionary.
Kind: instance method of Vector3
Returns: \* - Dictionary with {x,y,z}
| Param | Type | Description |
|---|---|---|
| minimized | Boolean |
If true, will not include keys that their values are 0. You can use fromDict on minimized dicts. |
Vector3Get vector with 0,0,0 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 1,1,1 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 0.5,0.5 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with -1,0,0 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 1,0,0 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 0,-1,0 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 0,1,0 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 0,0,1 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Get vector with 0,0,-1 values.
Kind: static method of Vector3
Returns: Vector3 - result vector.
Vector3Lerp between two vectors.
Kind: static method of Vector3
Returns: Vector3 - result vector.
| Param | Type | Description |
|---|---|---|
| p1 | Vector3 |
First vector. |
| p2 | Vector3 |
Second vector. |
| a | Number |
Lerp factor (0.0 - 1.0). |
NumberCalculate distance between two vectors.
Kind: static method of Vector3
Returns: Number - Distance between vectors.
| Param | Type | Description |
|---|---|---|
| p1 | Vector3 |
First vector. |
| p2 | Vector3 |
Second vector. |
Vector3Return cross product between two vectors.
Kind: static method of Vector3
Returns: Vector3 - Crossed vector.
| Param | Type | Description |
|---|---|---|
| p1 | Vector3 |
First vector. |
| p2 | Vector3 |
Second vector. |
Vector3Parse and return a vector object from string in the form of “x,y”.
Kind: static method of Vector3
Returns: Vector3 - Parsed vector.
| Param | Type | Description |
|---|---|---|
| str | String |
String to parse. |
Vector3Create vector from array of numbers.
Kind: static method of Vector3
Returns: Vector3 - Vector instance.
| Param | Type | Description |
|---|---|---|
| arr | Array.<Number> |
Array of numbers to create vector from. |
Vector3Create vector from a dictionary.
Kind: static method of Vector3
Returns: Vector3 - Newly created vector.
| Param | Type | Description |
|---|---|---|
| data | \* |
Dictionary with {x,y,z}. |
StringStringStringStringStringStringNumberNumberKind: global typedef