jsge
Version:
Javascript Game Engine
317 lines (263 loc) • 8.35 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="expires" content="Wen, 05 Jun 2024 07:01:00 GMT">
<title>JSDoc: Source: base/2d/DrawShapeObject.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="stage-title">Source: base/2d/DrawShapeObject.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { DRAW_TYPE } from "../../constants.js";
import { utils } from "../../index.js";
/**
* A base draw object.
*/
export class DrawShapeObject {
#x;
#y;
#bg;
/**
* @type {DRAW_TYPE}
*/
#type;
/**
* Is used for blending pixel arithmetic
* https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/blendFunc.
* @type {Array<number>}
*/
#blendFunc;
/**
* @type {number}
*/
#sortIndex = 0;
/**
* @type {number}
*/
#rotation = 0;
/**
* @type {number}
*/
#id = utils.generateUniqId();
/**
* @type {boolean}
*/
#isRemoved = false;
/**
* @type {undefined | number | null}
*/
#attachedMaskId;
/**
* @type {boolean}
*/
#isMask;
/**
* @type {boolean}
*/
#isOffsetTurnedOff = false;
/**
* @type {boolean}
*/
#isChanged = false;
/**
* @hideconstructor
*/
constructor(type, mapX, mapY, bgColor) {
this.#x = mapX;
this.#y = mapY;
this.#bg = bgColor;
this.#type = type;
}
/**
* Background color as rgba(r,g,b,a).
* @type {string}
*/
get bgColor() {
return this.#bg;
}
set bgColor(value) {
this.#bg = value;
}
/**
* @type {DRAW_TYPE}
*/
get type() {
return this.#type;
}
/**
* @type {number}
*/
get x() {
return this.#x;
}
/**
* @type {number}
*/
get y () {
return this.#y;
}
set x(posX) {
this.#x = posX;
}
set y(posY) {
this.#y = posY;
}
/**
* @type {number}
*/
get sortIndex () {
return this.#sortIndex;
}
set sortIndex(value) {
this.#sortIndex = value;
}
get blendFunc () {
return this.#blendFunc;
}
set blendFunc(value) {
this.#blendFunc = value;
}
/**
* @type {number}
*/
get rotation() {
return this.#rotation;
}
set rotation(value) {
this.#rotation = value;
}
/**
* @type {number}
*/
get id() {
return this.#id;
}
/**
* @type {boolean}
*/
get isRemoved() {
return this.#isRemoved;
}
/**
* Destroy object on next render iteration.
*/
destroy() {
this.#isRemoved = true;
}
get isMaskAttached() {
return !!this.#attachedMaskId;
}
/**
* @ignore
*/
get _maskId() {
return this.#attachedMaskId;
}
/**
*
* @param {DrawShapeObject} mask
*/
setMask(mask) {
mask._isMask = true;
this.#attachedMaskId = mask.id;
}
removeMask() {
this.#attachedMaskId = null;
}
set _isMask(isSet) {
this.#isMask = isSet;
}
get _isMask() {
return this.#isMask;
}
get isOffsetTurnedOff() {
return this.#isOffsetTurnedOff;
}
/**
* turn off offset for specific draw object
* gameStageData.centerCameraPosition() will take no effect on such object
* Can be used for something that should be always on screen: control buttons, overlay masks etc.
*/
turnOffOffset() {
this.#isOffsetTurnedOff = true;
}
/**
* @ignore
* @param {number} width
* @param {number} height
* @returns {Array<Array<number>>}
*/
_calculateRectVertices = (width, height) => {
const halfW = width/2,
halfH = height/2;
return [[-halfW, -halfH], [halfW, -halfH], [halfW, halfH], [-halfW, halfH]];
};
/**
* @param {number} radius
* @param {number} [angle = 2 * Math.PI]
* @param {number} [step = Math.PI/12]
* @returns {Array<number>}
* @ignore
*/
_interpolateConus(radius, angle = 2*Math.PI, step = Math.PI/14) {
let conusPolygonCoords = [0, 0];
for (let r = 0; r <= angle; r += step) {
let x2 = Math.cos(r) * radius,
y2 = Math.sin(r) * radius;
conusPolygonCoords.push(x2, y2);
}
return conusPolygonCoords;
}
/**
* @param {number} radius
* @param {number} [angle = 2 * Math.PI]
* @param {number} [step = Math.PI/12]
* @returns {Array<Array<number>>}
* @ignore
*/
_calculateConusBoundaries(radius, angle = 2*Math.PI, step = Math.PI/14) {
let conusPolygonCoords = [];
for (let r = 0; r <= angle; r += step) {
let x2 = Math.cos(r) * radius,
y2 = Math.sin(r) * radius;
conusPolygonCoords.push([x2, y2]);
}
return conusPolygonCoords;
}
/**
* @param {Array<Array<number>> | Array<{x:number, y:number}>} boundaries
* @returns {Array<Array<number>>}
* @ignore
*/
_convertVerticesArray(boundaries) {
if (typeof boundaries[0].x !== "undefined" && typeof boundaries[0].y !== "undefined") {
return utils.verticesArrayToArrayNumbers(boundaries);
} else {
return boundaries;
}
}
}</code></pre>
</article>
</section>
</div>
<nav>
<div class="switcher"><ul><li class="active"><a href="/">1.5.9</a></li></div>
<h2><a href="/">Home</a></h2><h3>Classes</h3><ul><li><a href="DrawCircleObject.html">DrawCircleObject</a></li><li><a href="DrawConusObject.html">DrawConusObject</a></li><li><a href="DrawImageObject.html">DrawImageObject</a></li><li><a href="DrawLineObject.html">DrawLineObject</a></li><li><a href="DrawObjectFactory.html">DrawObjectFactory</a></li><li><a href="DrawPolygonObject.html">DrawPolygonObject</a></li><li><a href="DrawRectObject.html">DrawRectObject</a></li><li><a href="DrawShapeObject.html">DrawShapeObject</a></li><li><a href="DrawTextObject.html">DrawTextObject</a></li><li><a href="DrawTiledLayer.html">DrawTiledLayer</a></li><li><a href="GameStage.html">GameStage</a></li><li><a href="GameStageData.html">GameStageData</a></li><li><a href="IExtension.html">IExtension</a></li><li><a href="INetwork.html">INetwork</a></li><li><a href="IRender.html">IRender</a></li><li><a href="ISystem.html">ISystem</a></li><li><a href="ISystemAudio.html">ISystemAudio</a></li><li><a href="RenderLoop.html">RenderLoop</a></li><li><a href="RenderLoopDebug.html">RenderLoopDebug</a></li><li><a href="System.html">System</a></li><li><a href="SystemSettings.html">SystemSettings</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-application_scheme.html">Application Scheme</a></li><li><a href="tutorial-assets_manager.html">Assets Manager</a></li><li><a href="tutorial-common_issues.html">Common Issues</a></li><li><a href="tutorial-how_to_add_and_use_audio.html">How to add and use audio</a></li><li><a href="tutorial-how_to_do_animations.html">How to Create Animations</a></li><li><a href="tutorial-how_to_load_and_use_tilemaps.html">How to Load and Use Tilemaps</a></li><li><a href="tutorial-quick_start.html">Quick Start</a></li><li><a href="tutorial-spine_animations.html">How to Add Spine Animations</a></li><li><a href="tutorial-stages_lifecycle.html">Stages Lifecycle</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Wed Jun 18 2025 06:53:54 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>