UNPKG

shaku

Version:

A simple and effective JavaScript game development framework that knows its place!

115 lines (101 loc) 2.65 kB
/** * Implement texture asset type. * * |-- copyright and license --| * @module Shaku * @file shaku\src\assets\texture_in_atlas_asset.js * @author Ronen Ness (ronenness@gmail.com | http://ronenness.com) * @copyright (c) 2021 Ronen Ness * @license MIT * |-- end copyright and license --| * */ 'use strict'; const TextureAssetBase = require("./texture_asset_base"); const Rectangle = require("../utils/rectangle"); /** * 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. */ class TextureInAtlasAsset extends TextureAssetBase { /** @inheritdoc */ constructor(url, texture, sourceRect, atlas) { super(url); this._texture = texture; this._sourceRect = sourceRect; this._atlas = atlas; } /** * Return the source rectangle in texture atlas. * @returns {Rectangle} Source rectangle. */ get sourceRectangle() { return this._sourceRect; } /** * Return the source rectangle in texture atlas, in normalized 0.0-1.0 values. * @returns {Rectangle} Source rectangle. */ get sourceRectangleNormalized() { if (!this._sourceRectNormalized) { this._sourceRectNormalized = new Rectangle( this._sourceRect.x / this.width, this._sourceRect.y / this.height, this._sourceRect.width / this.width, this._sourceRect.height / this.height ); } return this._sourceRectNormalized; } /** * Return the texture asset of this atlas texture. * @returns {TextureAsset} Texture asset. */ get texture() { return this._texture; } /** * Return the texture atlas class. * @returns {TextureAtlasAsset} Parent atlas. */ get atlas() { return this._atlas; } /** @inheritdoc */ get image() { return this.texture.image; } /** @inheritdoc */ get width() { return this.texture.width; } /** @inheritdoc */ get height() { return this.texture.height; } /** @inheritdoc */ get _glTexture() { return this.texture._glTexture; } /** @inheritdoc */ get valid() { return Boolean(this.texture.valid); } /** @inheritdoc */ destroy() { } } // export the asset type. module.exports = TextureInAtlasAsset;