UNPKG

66.6 kBHTMLView Raw
1<!DOCTYPE html>
2
3<html lang="en">
4<head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width">
7 <title>CrossBrowdy API documentation Source: CrossBase/audiovisual/image/CB_GraphicSpritesScene.js</title>
8
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
13
14 <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
16</head>
17
18<body style="min-width:800px; overflow-wrap:break-word; word-wrap:break-word; word-break:break-word; line-break:strict; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none;">
19
20<div class="navbar navbar-default navbar-fixed-top ">
21<div class="container">
22 <div class="navbar-header">
23 <a class="navbar-brand" href="index.html">CrossBrowdy API documentation</a>
24 <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25 <span class="icon-bar"></span>
26 <span class="icon-bar"></span>
27 <span class="icon-bar"></span>
28 </button>
29 </div>
30 <div class="navbar-collapse collapse" id="topNavigation">
31 <ul class="nav navbar-nav">
32
33 <li class="dropdown">
34 <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
35 <ul class="dropdown-menu inline">
36 <li><a href="CB_Arrays.html">CB_Arrays</a></li><li><a href="CB_AudioDetector.html">CB_AudioDetector</a></li><li><a href="CB_baseSymbols.html">CB_baseSymbols</a></li><li><a href="CB_Client.html">CB_Client</a></li><li><a href="CB_Collisions.html">CB_Collisions</a></li><li><a href="CB_Configuration.html">CB_Configuration</a></li><li><a href="CB_Configuration.CrossBase.html">CB_Configuration.CrossBase</a></li><li><a href="CB_Configuration.CrossBrowdy.html">CB_Configuration.CrossBrowdy</a></li><li><a href="CB_Controllers.html">CB_Controllers</a></li><li><a href="CB_Controllers_Proprietary.html">CB_Controllers_Proprietary</a></li><li><a href="CB_Controllers_Proprietary.WII.html">CB_Controllers_Proprietary.WII</a></li><li><a href="CB_Controllers_Proprietary.WII_U.html">CB_Controllers_Proprietary.WII_U</a></li><li><a href="CB_Device.html">CB_Device</a></li><li><a href="CB_Device.AmbientLight.html">CB_Device.AmbientLight</a></li><li><a href="CB_Device.Battery.html">CB_Device.Battery</a></li><li><a href="CB_Device.Location.html">CB_Device.Location</a></li><li><a href="CB_Device.Motion.html">CB_Device.Motion</a></li><li><a href="CB_Device.Orientation.html">CB_Device.Orientation</a></li><li><a href="CB_Device.Proximity.html">CB_Device.Proximity</a></li><li><a href="CB_Device.Vibration.html">CB_Device.Vibration</a></li><li><a href="CB_Elements.html">CB_Elements</a></li><li><a href="CB_Events.html">CB_Events</a></li><li><a href="CB_Keyboard.html">CB_Keyboard</a></li><li><a href="CB_Keyboard.chars.html">CB_Keyboard.chars</a></li><li><a href="CB_Keyboard.extended.html">CB_Keyboard.extended</a></li><li><a href="CB_Keyboard.keys.html">CB_Keyboard.keys</a></li><li><a href="CB_Modules.html">CB_Modules</a></li><li><a href="CB_Mouse.html">CB_Mouse</a></li><li><a href="CB_Mouse.CursorImage.html">CB_Mouse.CursorImage</a></li><li><a href="CB_Net.html">CB_Net</a></li><li><a href="CB_Net.Fetch.html">CB_Net.Fetch</a></li><li><a href="CB_Net.REST.html">CB_Net.REST</a></li><li><a href="CB_Net.Sockets.html">CB_Net.Sockets</a></li><li><a href="CB_Net.Sockets.SockJS.html">CB_Net.Sockets.SockJS</a></li><li><a href="CB_Net.XHR.html">CB_Net.XHR</a></li><li><a href="CB_Pointer.html">CB_Pointer</a></li><li><a href="CB_Screen.html">CB_Screen</a></li><li><a href="CB_Speaker.html">CB_Speaker</a></li><li><a href="CB_Touch.html">CB_Touch</a></li>
37 </ul>
38 </li>
39
40 <li class="dropdown">
41 <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
42 <ul class="dropdown-menu inline">
43 <li><a href="CB_AudioFile.html">CB_AudioFile</a></li><li><a href="CB_AudioFile_API.AAPI.html">CB_AudioFile_API.AAPI</a></li><li><a href="CB_AudioFile_API.ACMP.html">CB_AudioFile_API.ACMP</a></li><li><a href="CB_AudioFile_API.SM2.html">CB_AudioFile_API.SM2</a></li><li><a href="CB_AudioFile_API.WAAPI.html">CB_AudioFile_API.WAAPI</a></li><li><a href="CB_AudioFileCache.html">CB_AudioFileCache</a></li><li><a href="CB_AudioFileSprites.html">CB_AudioFileSprites</a></li><li><a href="CB_AudioFileSpritesPool.html">CB_AudioFileSpritesPool</a></li><li><a href="CB_Canvas.html">CB_Canvas</a></li><li><a href="CB_GraphicSprites.html">CB_GraphicSprites</a></li><li><a href="CB_GraphicSpritesScene.html">CB_GraphicSpritesScene</a></li>
44 </ul>
45 </li>
46
47 <li class="dropdown">
48 <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
49 <ul class="dropdown-menu inline">
50 <li><a href="global.html#CB_addCredits">CB_addCredits</a></li><li><a href="global.html#CB_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_baseToBase">CB_baseToBase</a></li><li><a href="global.html#CB_baseToInt">CB_baseToInt</a></li><li><a href="global.html#CB_br2nl">CB_br2nl</a></li><li><a href="global.html#CB_brToNl">CB_brToNl</a></li><li><a href="global.html#CB_combineArraysOrObjects">CB_combineArraysOrObjects</a></li><li><a href="global.html#CB_combineAutomatically">CB_combineAutomatically</a></li><li><a href="global.html#CB_combineJSON">CB_combineJSON</a></li><li><a href="global.html#CB_combineURIParameters">CB_combineURIParameters</a></li><li><a href="global.html#CB_combineURLParameters">CB_combineURLParameters</a></li><li><a href="global.html#CB_console">CB_console</a></li><li><a href="global.html#CB_copyObject">CB_copyObject</a></li><li><a href="global.html#CB_countDecimalDigits">CB_countDecimalDigits</a></li><li><a href="global.html#CB_countDecimalPart">CB_countDecimalPart</a></li><li><a href="global.html#CB_countDecimals">CB_countDecimals</a></li><li><a href="global.html#CB_countIntegerDigits">CB_countIntegerDigits</a></li><li><a href="global.html#CB_countIntegerPart">CB_countIntegerPart</a></li><li><a href="global.html#CB_credits">CB_credits</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_forceString">CB_forceString</a></li><li><a href="global.html#CB_forEach">CB_forEach</a></li><li><a href="global.html#CB_getBase64StringObject">CB_getBase64StringObject</a></li><li><a href="global.html#CB_getCookie">CB_getCookie</a></li><li><a href="global.html#CB_getDatum">CB_getDatum</a></li><li><a href="global.html#CB_getJSONPropertyValue">CB_getJSONPropertyValue</a></li><li><a href="global.html#CB_getLZStringObject">CB_getLZStringObject</a></li><li><a href="global.html#CB_getValueIndex">CB_getValueIndex</a></li><li><a href="global.html#CB_getValuePath">CB_getValuePath</a></li><li><a href="global.html#CB_includeJSFile">CB_includeJSFile</a></li><li><a href="global.html#CB_indexOf">CB_indexOf</a></li><li><a href="global.html#CB_init">CB_init</a></li><li><a href="global.html#CB_intToBase">CB_intToBase</a></li><li><a href="global.html#CB_isArray">CB_isArray</a></li><li><a href="global.html#CB_isEmail">CB_isEmail</a></li><li><a href="global.html#CB_isFileLocal">CB_isFileLocal</a></li><li><a href="global.html#CB_isString">CB_isString</a></li><li><a href="global.html#CB_lastIndexOf">CB_lastIndexOf</a></li><li><a href="global.html#CB_ltrim">CB_ltrim</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_nl2br">CB_nl2br</a></li><li><a href="global.html#CB_nlToBr">CB_nlToBr</a></li><li><a href="global.html#CB_numberFormat">CB_numberFormat</a></li><li><a href="global.html#CB_numberOfDecimalDigits">CB_numberOfDecimalDigits</a></li><li><a href="global.html#CB_numberOfDecimals">CB_numberOfDecimals</a></li><li><a href="global.html#CB_numberOfIntegerDigits">CB_numberOfIntegerDigits</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_parseJSON">CB_parseJSON</a></li><li><a href="global.html#CB_parseString">CB_parseString</a></li><li><a href="global.html#CB_regularExpressionString">CB_regularExpressionString</a></li><li><a href="global.html#CB_renderString">CB_renderString</a></li><li><a href="global.html#CB_replaceAll">CB_replaceAll</a></li><li><a href="global.html#CB_rtrim">CB_rtrim</a></li><li><a href="global.html#CB_scriptPath">CB_scriptPath</a></li><li><a href="global.html#CB_scriptPathCalculate">CB_scriptPathCalculate</a></li><li><a href="global.html#CB_setCookie">CB_setCookie</a></li><li><a href="global.html#CB_setDatum">CB_setDatum</a></li><li><a href="global.html#CB_sizeof">CB_sizeof</a></li><li><a href="global.html#CB_sizeOf">CB_sizeOf</a></li><li><a href="global.html#CB_stringifyJSON">CB_stringifyJSON</a></li><li><a href="global.html#CB_symmetricCall">CB_symmetricCall</a></li><li><a href="global.html#CB_symmetricCallClear">CB_symmetricCallClear</a></li><li><a href="global.html#CB_this">CB_this</a></li><li><a href="global.html#CB_trim">CB_trim</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li>
51 </ul>
52 </li>
53
54 </ul>
55
56 <div class="col-sm-3 col-md-3">
57 <form class="navbar-form" role="search">
58 <div class="input-group">
59 <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
60 <div class="input-group-btn">
61 <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
62 </div>
63 </div>
64 </form>
65 </div>
66
67 </div>
68
69</div>
70</div>
71
72
73<div class="container" id="toc-content" style="width:100%;">
74<div class="row" style="width:100%;">
75
76
77 <div class="col-md-12">
78
79 <div id="main">
80
81
82 <h1 class="page-title">Source: CrossBase/audiovisual/image/CB_GraphicSpritesScene.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Groups of graphic sprites management (2D or 3D). Internally, it manages {@link CB_GraphicSprites} objects. Contains the {@link CB_GraphicSpritesScene} class.
89 * @author Joan Alba Maldonado &lt;workindalian@gmail.com>
90 * @license Creative Commons Attribution 4.0 International. See more at {@link https://crossbrowdy.com/about#what_is_the_crossbrowdy_copyright_and_license}.
91 */
92
93
94/**
95 * An object with the information that belongs to a group of graphic sprites.
96 * @example
97 {
98 //'my_sprites_scene_1':
99 id: "my_sprites_scene_1",
100 srcType: CB_GraphicSprites.SRC_TYPES.IMAGE,
101 srcLeft: 10,
102 srcTop: 20,
103 srcWidth: 64,
104 srcHeight: 32,
105 left: 10,
106 top: 20,
107 width: 64,
108 height: 32,
109 data: { datum_1: "value_1", datum_2: 2, datum_3: [ "a", "b", "c" ] },
110 //Sprites groups:
111 spritesGroups:
112 [
113 //'my_sprites_1':
114 {
115 id: "my_sprites_1",
116 src: "path/to/image.gif",
117 sprites:
118 [
119 //'my_sprite_1':
120 {
121 id: "my_sprite_1",
122 subSprites:
123 [
124 //'my_subsprite_1':
125 { id: "my_subsprite_1", srcLeft: 10, srcTop: 20, zIndex: 1 },
126 //'my_subsprite_2':
127 { id: "my_subsprite_2", srcLeft: 20, srcTop: 40, zIndex: 2 }
128 ]
129 },
130 //'my_sprite_2':
131 {
132 id: "my_sprite_2",
133 subSprites:
134 [
135 //'my_subsprite_3':
136 { id: "my_subsprite_3", srcLeft: 30, srcTop: 60, zIndex: 1 },
137 //'my_subsprite_4':
138 { id: "my_subsprite_4", srcLeft: 40, srcTop: 80, zIndex: 2 }
139 ]
140 }
141 ]
142 },
143 //'my_sprites_2':
144 {
145 id: "my_sprites_2",
146 src: "path/to/image2.gif",
147 sprites:
148 [
149 //'my_sprite_3':
150 {
151 id: "my_sprite_3",
152 subSprites:
153 [
154 //'my_subsprite_1':
155 { id: "my_subsprite_5", srcLeft: 10, srcTop: 20, zIndex: 1 },
156 //'my_subsprite_2':
157 { id: "my_subsprite_6", srcLeft: 20, srcTop: 40, zIndex: 2 }
158 ]
159 },
160 //'my_sprite_4':
161 {
162 id: "my_sprite_4",
163 subSprites:
164 [
165 //'my_subsprite_3':
166 { id: "my_subsprite_7", srcLeft: 30, srcTop: 60, zIndex: 1 },
167 //'my_subsprite_4':
168 { id: "my_subsprite_8", srcLeft: 40, srcTop: 80, zIndex: 2 }
169 ]
170 }
171 ]
172 }
173 ]
174 }
175 * @memberof CB_GraphicSpritesScene
176 * @typedef {Object} CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT
177 * @property {string|*} [id='CB_GraphicSpritesScene_' + CB_GraphicSpritesScene._idUnique++] - Identifier of the sprites groups object and also for the graphic sprites scene (also used as the {@link CB_GraphicSprites.id} property for the {@link CB_GraphicSpritesScene} object). It should be unique. Recommended. It must be a value which evaluates to true. By default, it is generated automatically (with an internal counter).
178 * @property {*} [src=""] - The value for the "src" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
179 * @property {string} [srcType={@link CB_GraphicSprites.SRC_TYPES_DEFAULT}] - The value for the "srcType" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects. It should point to a property of the {@link CB_GraphicSprites.SRC_TYPES} object. You can use other values of the {@link CB_GraphicSprites.SRC_TYPES} object or create new ones.
180 * @property {number} [srcLeft={@link CB_GraphicSprites.LEFT_SOURCE_DEFAULT}] - The value for the "srcLeft" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
181 * @property {number} [srcTop={@link CB_GraphicSprites.TOP_SOURCE_DEFAULT}] - The value for the "srcTop" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
182 * @property {number} [srcWidth={@link CB_GraphicSprites.WIDTH_SOURCE_DEFAULT}] - The value for the "srcWidth" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
183 * @property {number} [srcHeight={@link CB_GraphicSprites.HEIGHT_SOURCE_DEFAULT}] - The value for the "srcHeight" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
184 * @property {number} [left={@link CB_GraphicSprites.LEFT_DEFAULT}] - The value for the "left" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
185 * @property {number} [top={@link CB_GraphicSprites.TOP_DEFAULT}] - The value for the "top" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
186 * @property {number} [width={@link CB_GraphicSprites.WIDTH_DEFAULT}] - The value for the "width" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
187 * @property {number} [height={@link CB_GraphicSprites.HEIGHT_DEFAULT}] - The value for the "height" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
188 * @property {number} [zIndex={@link CB_GraphicSprites.ZINDEX_DEFAULT}] - The value for the "zIndex" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
189 * @property {boolean} [disabled=false] - The value for the "disabled" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
190 * @property {object} [data={ 'that' : CB_GraphicSprites.SPRITES_GROUPS_OBJECT, 'getThis' = function() { return this.that; } }] - Object with any additional data desired which can be any kind. It will always have a "that" property pointing to the {@link CB_GraphicSprites.SPRITES_GROUPS_OBJECT} object where it belongs to and a function in its "getThis" property returning the same value (added automatically). These properties ("that" and "getThis") cannot be overridden. The value given will also be used for the "data" property which will be used as default if not provided (or the provided one was wrong) in the given {@link CB_GraphicSprites.SPRITES_OBJECT} objects (in the "spritesGroups" property), when creating the internal {@link CB_GraphicSprites} objects.
191 * @property {array} [spritesGroups=[]] - Numeric array containing {@link CB_GraphicSprites.SPRITES_OBJECT} objects with all the sprites groups that are useful for creating the internal {@link CB_GraphicSprites} objects. Recommended at least to provide one {@link CB_GraphicSprites.SPRITES_OBJECT} object in the first index.
192 * @property {*} [parent=undefined] - Property pointing to or containing its parent (also used as the {@link CB_GraphicSpritesScene.parent} property for the {@link CB_GraphicSpritesScene} object).
193 * @property {array} items - Read-only numeric array containing {@link CB_GraphicSprites} objects created internally. Their "parent" property will be set to point the current {@link CB_GraphicSpritesScene} object which contains them.
194 * @property {array} itemsByZIndex - Read-only property containing a numeric array of all the {@link CB_GraphicSprites} objects ordered by their z-index ("zIndex" property). It is updated automatically when the z-index of a sprite is set with its {@link CB_GraphicSprites#setZIndex} method or when inserting/removing {@link CB_GraphicSprites} objects through the {@link CB_GraphicSpritesScene#insertSpritesGroups}, {@link CB_GraphicSpritesScene#insertSpritesGroup}, {@link CB_GraphicSpritesScene#removeSpritesGroup} or {@link CB_GraphicSpritesScene#removeSpritesGroupById} methods.
195 * @property {boolean} [byReference_DEFAULT=false] - Default value to use as the "byReference" parameter for the constructor and for the {@link CB_GraphicSpritesScene#insertSpritesGroups} method. If a boolean value is not provided, it will be parsed to boolean (resulting undefined to be false).
196 * @property {CB_GraphicSpritesScene} container - Read-only property pointing to the {@link CB_GraphicSpritesScene} object which contains it.
197 * @property {boolean} isSpritesGroups - Read-only property which is always set to true to help identify this type of object.
198 * @property {'spritesGroups'} type - Read-only property indicating the type of object (always "spritesGroups").
199 */
200
201
202/**
203 * Class to manage different groups of graphic sprites (2D or 3D). Internally, it manages {@link CB_GraphicSprites} objects.
204 * @class
205 * @classdesc Class to manage different groups of graphic sprites (2D or 3D). Internally, it manages {@link CB_GraphicSprites} objects.
206 * @param {CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} [spritesGroups] - Object with the desired groups of sprites. The information will be used for the {@link CB_GraphicSpritesScene#spritesGroups} property. Used as the "spritesGroups" parameter when calling the {@link CB_GraphicSpritesScene#insertSpritesGroups} method internally.
207 * @param {boolean} [byReference=false] - This value will be used as the "byReference" parameter of the constructor when creating the new internal {@link CB_GraphicSprites} objects. If a boolean value is not provided, it will use the value of the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT.byReference_DEFAULT} property of the given {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object (parsed to boolean).
208 * @returns {CB_GraphicSpritesScene} Returns a new {@link CB_GraphicSpritesScene} object.
209 * @todo Think about a "createCopy" parameter on different the insert methods (to insert sprites groups/graphic sprites objects, etc.) so it will make a copy of the object to avoid using/modifying the original one. If the "createCopy" is set to false, it should always use the object as reference (using/modifying it).
210 * @todo Think about a method to remove a sprite group object when the same sprite group is received by parameter. The same to remove a {@link CB_GraphicSprites} object, receiving a {@link CB_GraphicSprites} object by parameter. The same to remove the sprites groups object, receiving a sprites groups object by parameter. Only remove them if they match exactly.
211 * @todo Think about a method to insert {@link CB_GraphicSprites} object directly. The same with a method that inserts many {@link CB_GraphicSprites} objects (receiving an array with them).
212 */
213var CB_GraphicSpritesScene = function(spritesGroups, byReference)
214{
215 //Creates an instance of this object and returns it in the case that it is being called from an unexpected context:
216 if (this === window || !(this instanceof CB_GraphicSpritesScene)) { return new CB_GraphicSpritesScene(spritesGroups, byReference); }
217
218 //Properties and variables:
219 /**
220 * Identifier of the sprites groups object (the "id" property of the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} stored in the {@link CB_GraphicSpritesScene#spritesGroups} property) and the {@link CB_GraphicSpritesScene} object itself (same one). It should be unique. It must be a value which evaluates to true. By default, it is generated automatically (with an internal counter).
221 * @var
222 * @readonly
223 * @type {string|*}
224 * @default 'CB_GraphicSpritesScene_' + CB_GraphicSpritesScene._idUnique++
225 */
226 this.id = "";
227
228 /**
229 * Property pointing to or containing its parent. It is the same as the "parent" property of the {@link CB_GraphicSprites.SPRITES_GROUPS_OBJECT} stored in the {@link CB_GraphicSprites#spritesGroups} property.
230 * @var
231 * @readonly
232 * @type {*}
233 * @default
234 */
235 this.parent = undefined;
236
237
238 /**
239 * Object containing all the internally-created {@link CB_GraphicSprites} objects and their information.
240 * @var
241 * @readonly
242 * @type {SPRITES_GROUPS_OBJECT}
243 * @default
244 */
245 this.spritesGroups = {};
246
247 //Calls the constructor of the object when creates an instance:
248 return this._init(spritesGroups, byReference);
249}
250
251
252//Constants:
253/**
254 * Property which is always set to true to help identify this type of object.
255 * @constant
256 * @type {boolean}
257 * @default
258 */
259CB_GraphicSpritesScene.prototype.isSpritesScene = true;
260
261
262/**
263 * Indicates the type of object (always "spritesScene").
264 * @constant
265 * @type {string}
266 * @default
267 */
268CB_GraphicSpritesScene.prototype.type = "spritesScene";
269
270
271//Variables:
272CB_GraphicSpritesScene._idUnique = 0; //Counter to make the sprites group id unique.
273
274
275//Constructor:
276CB_GraphicSpritesScene.prototype._init = function(spritesGroups, byReference)
277{
278 this.insertSpritesGroups(spritesGroups, byReference);
279 return this;
280}
281
282
283/**
284 * Destroys the graphic sprites scene object (removing all the sprites groups and the internal {@link CB_GraphicSprites} objects, etc.) and frees memory.
285 * @function
286 */
287CB_GraphicSpritesScene.prototype.destructor = function()
288{
289 //Destroys all the internal CB_GraphicSprites objects:
290 this.executeFunctionAll(function() { this.destructor(); });
291
292 //Resets properties to their default value:
293 this.removeSpritesGroups();
294}
295
296
297/**
298 * Alias for {@link CB_GraphicSpritesScene#removeSpritesGroups}.
299 * @function CB_GraphicSpritesScene#removeAll
300 * @see {@link CB_GraphicSpritesScene#removeSpritesGroups}
301 */
302/**
303 * Alias for {@link CB_GraphicSpritesScene#removeSpritesGroups}.
304 * @function CB_GraphicSpritesScene#removeSpritesGroupsAll
305 * @see {@link CB_GraphicSpritesScene#removeSpritesGroups}
306 */
307/**
308 * Removes all the sprites groups (and all the {@link CB_GraphicSprites} objects) by clearing the {@link CB_GraphicSprites#spritesGroups} property.
309 * @function
310 */
311CB_GraphicSpritesScene.prototype.removeSpritesGroups = CB_GraphicSpritesScene.prototype.removeSpritesGroupsAll = CB_GraphicSpritesScene.prototype.removeAll = function()
312{
313 this.spritesGroups = {};
314}
315
316
317/**
318 * Adds the desired groups of graphic sprites. Calls the {@link CB_GraphicSpritesScene#insertSpritesGroup} and {@link CB_GraphicSpritesScene#updateGraphicSpritesByZIndex} methods internally.
319 * @function
320 * @param {CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} [spritesGroups] - Object with the desired sprites groups. They will be stored in the "{@link CB_GraphicSpritesScene#spritesGroups}.spritesGroups" property and the {@link CB_GraphicSprites} objects created internally will be stored in the "{@link CB_GraphicSpritesScene#spritesGroups}.items" property.
321 * @param {boolean} [byReference=!!{@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT.byReference_DEFAULT}] - This value will be used as the "byReference" parameter of the constructor when creating the new internal {@link CB_GraphicSprites} objects. If a boolean value is not provided, it will use the value of the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT.byReference_DEFAULT} property of the given {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object (parsed to boolean).
322 * @returns {CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} Returns the {@link CB_GraphicSpritesScene#spritesGroups} property after updating it.
323 */
324CB_GraphicSpritesScene.prototype.insertSpritesGroups = function(spritesGroups, byReference)
325{
326 //Sets the properties (sanitizing them):
327 this.spritesGroups = this.spritesGroups || {};
328 spritesGroups = spritesGroups || {};
329 this.spritesGroups.isSpritesGroups = true;
330 this.spritesGroups.type = "spritesGroups";
331 this.spritesGroups.container = this;
332 this.parent = this.spritesGroups.parent = spritesGroups.parent;
333 this.id = this.spritesGroups.id = spritesGroups.id = spritesGroups.id || "CB_GraphicSpritesScene_" + CB_GraphicSpritesScene._idUnique++;
334 this.spritesGroups.src = spritesGroups.src = spritesGroups.src || !isNaN(spritesGroups.src) &amp;&amp; spritesGroups.src !== null ? spritesGroups.src : "";
335 this.spritesGroups.srcType = spritesGroups.srcType = spritesGroups.srcType || CB_GraphicSprites.SRC_TYPES_DEFAULT;
336 spritesGroups.srcLeft = parseFloat(spritesGroups.srcLeft);
337 this.spritesGroups.srcLeft = spritesGroups.srcLeft = !isNaN(spritesGroups.srcLeft) ? spritesGroups.srcLeft : parseFloat(CB_GraphicSprites.LEFT_SOURCE_DEFAULT) || 0;
338 spritesGroups.left = parseFloat(spritesGroups.left);
339 this.spritesGroups.left = spritesGroups.left = !isNaN(spritesGroups.left) ? spritesGroups.left : parseFloat(CB_GraphicSprites.LEFT_DEFAULT) || 0;
340 spritesGroups.srcTop = parseFloat(spritesGroups.srcTop);
341 this.spritesGroups.srcTop = spritesGroups.srcTop = !isNaN(spritesGroups.srcTop) ? spritesGroups.srcTop : parseFloat(CB_GraphicSprites.TOP_SOURCE_DEFAULT) || 0;
342 spritesGroups.top = parseFloat(spritesGroups.top);
343 this.spritesGroups.top = spritesGroups.top = !isNaN(spritesGroups.top) ? spritesGroups.top : parseFloat(CB_GraphicSprites.TOP_DEFAULT) || 0;
344 spritesGroups.srcWidth = parseFloat(spritesGroups.srcWidth);
345 this.spritesGroups.srcWidth = spritesGroups.srcWidth = !isNaN(spritesGroups.srcWidth) ? spritesGroups.srcWidth : parseFloat(CB_GraphicSprites.WIDTH_SOURCE_DEFAULT) || 0;
346 spritesGroups.width = parseFloat(spritesGroups.width);
347 this.spritesGroups.width = spritesGroups.width = !isNaN(spritesGroups.width) ? spritesGroups.width : parseFloat(CB_GraphicSprites.WIDTH_DEFAULT) || 0;
348 spritesGroups.srcHeight = parseFloat(spritesGroups.srcHeight);
349 this.spritesGroups.srcHeight = spritesGroups.srcHeight = !isNaN(spritesGroups.srcHeight) ? spritesGroups.srcHeight : parseFloat(CB_GraphicSprites.HEIGHT_SOURCE_DEFAULT) || 0;
350 spritesGroups.height = parseFloat(spritesGroups.height);
351 this.spritesGroups.height = spritesGroups.height = !isNaN(spritesGroups.height) ? spritesGroups.height : parseFloat(CB_GraphicSprites.HEIGHT_DEFAULT) || 0;
352 spritesGroups.zIndex = parseFloat(spritesGroups.zIndex);
353 this.spritesGroups.zIndex = spritesGroups.zIndex = !isNaN(spritesGroups.zIndex) ? spritesGroups.zIndex : parseFloat(CB_GraphicSprites.ZINDEX_DEFAULT) || 0;
354 this.spritesGroups.data = typeof(spritesGroups.data) === "object" &amp;&amp; spritesGroups.data !== null ? CB_copyObject(spritesGroups.data, false) : {}; //Accepts any object but not other values.
355 this.spritesGroups.data.that = this.spritesGroups;
356 this.spritesGroups.data.getThis = function() { return this.that; };
357
358 spritesGroups.spritesGroups = CB_isArray(spritesGroups.spritesGroups) ? spritesGroups.spritesGroups : [];
359
360 //Inserts the given sprites groups, one by one:
361 byReference = (byReference === true || byReference === false) ? byReference : !!spritesGroups.byReference_DEFAULT;
362 var spritesGroupsLength = spritesGroups.spritesGroups.length;
363 for (var x = 0; x &lt; spritesGroupsLength; x++)
364 {
365 this.insertSpritesGroup(spritesGroups.spritesGroups[x], true, byReference);
366 }
367
368 //Updates the array with the CB_GraphicSprites ordered by z-index:
369 this.updateGraphicSpritesByZIndex();
370
371 //Returns the sprites:
372 return this.spritesGroups;
373}
374
375
376/**
377 * Alias for {@link CB_GraphicSpritesScene#updateGraphicSpritesByZIndex}.
378 * @function CB_GraphicSpritesScene#updateItemsByZIndex
379 * @see {@link CB_GraphicSpritesScene#updateGraphicSpritesByZIndex}
380 */
381/**
382 * Updates (sorts again) the "itemsByZIndex" property (which is an array with the {@link CB_GraphicSprites} objects ordered by z-index, whose data comes from the array in the "items" property of the {@link CB_GraphicSpritesScene#spritesGroups} object) of the {@link CB_GraphicSpritesScene#spritesGroups} object.
383 * @function
384 * @returns {array} Returns the "itemsByZIndex" array of the {@link CB_GraphicSpritesScene#spritesGroups} object after updating it. Returns null if the property could not be obtained or updated.
385 */
386CB_GraphicSpritesScene.prototype.updateGraphicSpritesByZIndex = CB_GraphicSpritesScene.prototype.updateItemsByZIndex = function()
387{
388 this.spritesGroups.items = this.spritesGroups.items || null;
389 if (this.spritesGroups.items)
390 {
391 var spritesGroupLength = this.spritesGroups.items.length;
392 if (spritesGroupLength)
393 {
394 var elementIndex = null;
395 this.spritesGroups.itemsByZIndex = [];
396 for (var x = 0; x &lt; spritesGroupLength; x++)
397 {
398 elementIndex = CB_GraphicSpritesScene._choosePositionByZIndex(this.spritesGroups.itemsByZIndex, this.spritesGroups.items[x]);
399 this.spritesGroups.itemsByZIndex = CB_Arrays.insertElement(this.spritesGroups.itemsByZIndex, elementIndex, this.spritesGroups.items[x]);
400 this.spritesGroups.items[x].positionByZIndex = elementIndex;
401 }
402 return this.spritesGroups.itemsByZIndex;
403 }
404 }
405 return null;
406}
407
408
409/**
410 * Alias for {@link CB_GraphicSpritesScene#removeSpritesGroup}.
411 * @function CB_GraphicSpritesScene#remove
412 * @see {@link CB_GraphicSpritesScene#removeSpritesGroup}
413 */
414/**
415 * Alias for {@link CB_GraphicSpritesScene#removeSpritesGroup}.
416 * @function CB_GraphicSpritesScene#removeGraphicSprites
417 * @see {@link CB_GraphicSpritesScene#removeSpritesGroup}
418 */
419/**
420 * Removes a sprites group and its {@link CB_GraphicSprites} object by its index (its position in the {@link CB_GraphicSpritesScene#spritesGroups.items} array). Calls the {@link CB_GraphicSpritesScene#updateGraphicSpritesByZIndex} method internally.
421 * @function
422 * @param {integer} [index=0] - The index where the {@link CB_GraphicSprites} object is located (its position in the {@link CB_GraphicSpritesScene#spritesGroups.items} array).
423 * @returns {boolean} Returns true if the {@link CB_GraphicSprites} object has been deleted from the graphic sprites scene object or false otherwise.
424 */
425CB_GraphicSpritesScene.prototype.removeSpritesGroup = CB_GraphicSpritesScene.prototype.removeGraphicSprites = CB_GraphicSpritesScene.prototype.remove = function(index)
426{
427 var removed = false;
428 var spritesGroupsLeft = CB_Arrays.removeElementByPosition(this.spritesGroups.items, index, function() { removed = true; });
429 if (removed)
430 {
431 this.spritesGroups.spritesGroups = CB_Arrays.removeElementByPosition(this.spritesGroups.spritesGroups, index);
432 this.spritesGroups.items = spritesGroupsLeft;
433
434 //Updates the array with the CB_GraphicSprites ordered by z-index:
435 this.updateGraphicSpritesByZIndex();
436 }
437 return removed;
438}
439
440
441/**
442 * Alias for {@link CB_GraphicSpritesScene#removeSpritesGroupById}.
443 * @function CB_GraphicSpritesScene#removeById
444 * @see {@link CB_GraphicSpritesScene#removeSpritesGroupById}
445 */
446/**
447 * Alias for {@link CB_GraphicSpritesScene#removeSpritesGroupById}.
448 * @function CB_GraphicSpritesScene#removeGraphicSpritesById
449 * @see {@link CB_GraphicSpritesScene#removeSpritesGroupById}
450 */
451/**
452 * Removes a sprites group and its {@link CB_GraphicSprites} object by its identifier. Calls the {@link CB_GraphicSpritesScene#updateGraphicSpritesByZIndex} method internally.
453 * @function
454 * @param {string|*} [id=undefined] - The identifier of the {@link CB_GraphicSprites} object.
455 * @returns {boolean} Returns true if the {@link CB_GraphicSprites} object has been deleted from the graphic sprites scene object or false otherwise.
456 * @todo Optimize it (perhaps using a cache matching the IDs with their position, maybe using the "position" or "positionByZIndex" properties).
457 */
458CB_GraphicSpritesScene.prototype.removeSpritesGroupById = CB_GraphicSpritesScene.prototype.removeGraphicSpritesById = CB_GraphicSpritesScene.prototype.removeById = function(id)
459{
460 var removed = false;
461 var index = null;
462 var spritesGroupsLeft = CB_Arrays.removeDuplicated(this.spritesGroups.items, function(value, position, array) { if (value &amp;&amp; value.id === id) { removed = true; index = position; return true; }; return false; }, true);
463 if (removed)
464 {
465 if (index !== null) { this.spritesGroups.spritesGroups = CB_Arrays.removeElementByPosition(this.spritesGroups.spritesGroups, index); }
466 this.spritesGroups.items = spritesGroupsLeft;
467
468 //Updates the array with the CB_GraphicSprites ordered by z-index:
469 this.updateGraphicSpritesByZIndex();
470 }
471 return removed;
472}
473
474
475/**
476 * Object used as the returning value of the {@link CB_GraphicSpritesScene#insertSpritesGroup} method.
477 * @memberof CB_GraphicSpritesScene
478 * @typedef {Object} CB_GraphicSpritesScene.insertSpritesGroup_OBJECT
479 * @property {CB_GraphicSprites.SPRITES_OBJECT} spritesGroup - The {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} which has been inserted (it could have been modified/sanitized from the given one and some missing properties or those which were wrong could have been inherited) and was used to create the internal {@link CB_GraphicSprites} object when calling its constructor.
480 * @property {CB_GraphicSprites} item - The {@link CB_GraphicSprites} object created and inserted from the {@link CB_GraphicSprites.SPRITES_OBJECT}.
481 */
482
483/**
484 * Alias for {@link CB_GraphicSpritesScene#insertSpritesGroup}.
485 * @function CB_GraphicSpritesScene#insert
486 * @see {@link CB_GraphicSpritesScene#insertSpritesGroup}
487 */
488/**
489 * Adds the desired group of graphic sprites. Creates internal {@link CB_GraphicSprites} objects.
490 * @function
491 * @param {CB_GraphicSprites.SPRITES_OBJECT} [spritesGroup] - Object with the desired sprites group. It will be stored in the "{@link CB_GraphicSpritesScene#spritesGroups}.spritesGroups" property and the {@link CB_GraphicSprites} object created internally will be stored in the "{@link CB_GraphicSpritesScene#spritesGroups}.items" property.
492 * @param {boolean} [avoidUpdatingGraphicSpritesByZIndex=false] - If set to true, it will not call the {CB_GraphicSpritesScene#updateGraphicSpritesByZIndex} method internally. Internal usage recommended only.
493 * @param {boolean} [byReference=false] - This value will be used as the "byReference" parameter of the constructor when creating the new internal {@link CB_GraphicSprites} objects.
494 * @returns {CB_GraphicSpritesScene.insertSpritesGroup_OBJECT} Returns an object whose "spritesGroup" property contains the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} which has been inserted (it could have been modified/sanitized from the given one and some missing properties or those which were wrong could have been inherited) and was used to create the internal {@link CB_GraphicSprites} object when calling its constructor and the "item" property contains the {@link CB_GraphicSprites} object created and inserted.
495 */
496CB_GraphicSpritesScene.prototype.insertSpritesGroup = CB_GraphicSpritesScene.prototype.insert = function(spritesGroup, avoidUpdatingGraphicSpritesByZIndex, byReference)
497{
498 //Sets the properties (sanitizing them):
499 this.spritesGroups = this.spritesGroups || {};
500 spritesGroup = spritesGroup || {};
501 spritesGroup.parent = this; //Overwrites the parent to point to the CB_GraphicSprites itself which will contain it.
502 spritesGroup.src = spritesGroup.src || !isNaN(spritesGroup.src) &amp;&amp; spritesGroup.src !== null ? spritesGroup.src : this.spritesGroups.src || !isNaN(this.spritesGroups.src) &amp;&amp; this.spritesGroups.src !== null ? this.spritesGroups.src : "";
503 spritesGroup.srcType = spritesGroup.srcType || this.spritesGroups.srcType || CB_GraphicSprites.SRC_TYPES_DEFAULT;
504 spritesGroup.srcLeft = parseFloat(spritesGroup.srcLeft);
505 spritesGroup.srcLeft = !isNaN(spritesGroup.srcLeft) ? spritesGroup.srcLeft : parseFloat(this.spritesGroups.srcLeft);
506 spritesGroup.srcLeft = !isNaN(spritesGroup.srcLeft) ? spritesGroup.srcLeft : parseFloat(CB_GraphicSprites.LEFT_SOURCE_DEFAULT) || 0;
507 spritesGroup.left = parseFloat(spritesGroup.left);
508 spritesGroup.left = !isNaN(spritesGroup.left) ? spritesGroup.left : parseFloat(this.spritesGroups.left);
509 spritesGroup.left = !isNaN(spritesGroup.left) ? spritesGroup.left : parseFloat(CB_GraphicSprites.LEFT_DEFAULT) || 0;
510 spritesGroup.srcTop = parseFloat(spritesGroup.srcTop);
511 spritesGroup.srcTop = !isNaN(spritesGroup.srcTop) ? spritesGroup.srcTop : parseFloat(this.spritesGroups.srcTop);
512 spritesGroup.srcTop = !isNaN(spritesGroup.srcTop) ? spritesGroup.srcTop : parseFloat(CB_GraphicSprites.TOP_SOURCE_DEFAULT) || 0;
513 spritesGroup.top = parseFloat(spritesGroup.top);
514 spritesGroup.top = !isNaN(spritesGroup.top) ? spritesGroup.top : parseFloat(this.spritesGroups.top);
515 spritesGroup.top = !isNaN(spritesGroup.top) ? spritesGroup.top : parseFloat(CB_GraphicSprites.TOP_DEFAULT) || 0;
516 spritesGroup.srcWidth = parseFloat(spritesGroup.srcWidth);
517 spritesGroup.srcWidth = !isNaN(spritesGroup.srcWidth) ? spritesGroup.srcWidth : parseFloat(this.spritesGroups.srcWidth);
518 spritesGroup.srcWidth = !isNaN(spritesGroup.srcWidth) ? spritesGroup.srcWidth : parseFloat(CB_GraphicSprites.WIDTH_SOURCE_DEFAULT) || 0;
519 spritesGroup.width = parseFloat(spritesGroup.width);
520 spritesGroup.width = !isNaN(spritesGroup.width) ? spritesGroup.width : parseFloat(this.spritesGroups.width);
521 spritesGroup.width = !isNaN(spritesGroup.width) ? spritesGroup.width : parseFloat(CB_GraphicSprites.WIDTH_DEFAULT) || 0;
522 spritesGroup.srcHeight = parseFloat(spritesGroup.srcHeight);
523 spritesGroup.srcHeight = !isNaN(spritesGroup.srcHeight) ? spritesGroup.srcHeight : parseFloat(this.spritesGroups.srcHeight);
524 spritesGroup.srcHeight = !isNaN(spritesGroup.srcHeight) ? spritesGroup.srcHeight : parseFloat(CB_GraphicSprites.HEIGHT_SOURCE_DEFAULT);
525 spritesGroup.height = parseFloat(spritesGroup.height);
526 spritesGroup.height = !isNaN(spritesGroup.height) ? spritesGroup.height : parseFloat(this.spritesGroups.height);
527 spritesGroup.height = !isNaN(spritesGroup.height) ? spritesGroup.height : parseFloat(CB_GraphicSprites.HEIGHT_DEFAULT) || 0;
528 spritesGroup.zIndex = parseFloat(spritesGroup.zIndex);
529 spritesGroup.zIndex = !isNaN(spritesGroup.zIndex) ? spritesGroup.zIndex : parseFloat(this.spritesGroups.zIndex);
530 spritesGroup.zIndex = !isNaN(spritesGroup.zIndex) ? spritesGroup.zIndex : parseFloat(CB_GraphicSprites.ZINDEX_DEFAULT) || 0;
531 spritesGroup.disabled = !!spritesGroup.disabled || false;
532 spritesGroup.data = typeof(spritesGroup.data) === "object" &amp;&amp; spritesGroup.data !== null ? spritesGroup.data : {}; //this.spritesGroups.data;
533 if (typeof(this.spritesGroups.data) === "object" &amp;&amp; this.spritesGroups.data !== null) { spritesGroup.data = CB_combineJSON(this.spritesGroups.data, spritesGroup.data); } //Combine objects.
534 spritesGroup.data = typeof(spritesGroup.data) === "object" &amp;&amp; spritesGroup.data !== null ? CB_copyObject(spritesGroup.data, false) : {}; //Note: the CB_GraphicSprites class will add the "that" and "getThis" properties to the "data".
535
536 //Creates and inserts the sprites group:
537 this.spritesGroups.items = this.spritesGroups.items || [];
538 this.spritesGroups.spritesGroups = this.spritesGroups.spritesGroups || [];
539 var item = new CB_GraphicSprites(spritesGroup, byReference);
540 var position = this.getGraphicSpritesIndexById(item.id); //If there is a sprites group with the same ID, it will be replaced by the new one (in the same position).
541 position = position !== -1 ? position : this.spritesGroups.items.length;
542 item.position = position;
543 this.spritesGroups.items[position] = item;
544 spritesGroup.isSpritesGroup = true; //Adds the "isSpritesGroup" property to the sprites groups object.
545 spritesGroup.type = "spritesGroup"; //Adds the "type" property to the sprites groups object.
546 this.spritesGroups.spritesGroups[position] = spritesGroup; //Overrides the sprites groups object, sanitized.
547
548 if (!avoidUpdatingGraphicSpritesByZIndex) { this.updateGraphicSpritesByZIndex(); }
549
550 //Returns the sprites:
551 return { "spritesGroup" : spritesGroup, "item" : item };
552}
553
554
555//Returns the position that an element (subsprites group, sprite or sub-sprite) should have in a given array, having in mind that they are sorted by by z-index in that array (ascending order):
556CB_GraphicSpritesScene._choosePositionByZIndex = function(array, element)
557{
558 if (array &amp;&amp; element)
559 {
560 var arrayLength = array.length;
561 if (arrayLength)
562 {
563 for (var x = 0; x &lt; arrayLength; x++)
564 {
565 if (array[x] &amp;&amp; array[x].zIndex > element.zIndex) { return x; }
566 }
567 return array.length; //By default, best position is at the end of the array (as a new element).
568 }
569 }
570 return 0;
571}
572
573
574/**
575 * Alias for {@link CB_GraphicSpritesScene#getSpritesGroups}.
576 * @function CB_GraphicSpritesScene#getSpritesGroupsAll
577 * @see {@link CB_GraphicSpritesScene#getSpritesGroups}
578 */
579/**
580 * Gets the sprites groups object (the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object which is in the {@link CB_GraphicSpritesScene#spritesGroups} property), if any.
581 * @function
582 * @param {*} [returnValueOnFail=undefined] - The value we want it to return in the case that no value is found. If not provided, undefined will be returned.
583 * @returns {CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT|*} Returns the sprites groups object (the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object which is in the {@link CB_GraphicSpritesScene#spritesGroups} property), if any, or the value of "returnValueOnFail" otherwise.
584 */
585CB_GraphicSpritesScene.prototype.getSpritesGroups = CB_GraphicSpritesScene.prototype.getSpritesGroupsAll = function(returnValueOnFail)
586{
587 return this.spritesGroups ? this.spritesGroups : returnValueOnFail;
588}
589
590
591/**
592 * Alias for {@link CB_GraphicSpritesScene#getGraphicSpritesAll}.
593 * @function CB_GraphicSpritesScene#getAll
594 * @see {@link CB_GraphicSpritesScene#getGraphicSpritesAll}
595 */
596/**
597 * Gets all the sprites graphic objects (the "items" property of the internal {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object, if any).
598 * @function
599 * @param {boolean} [orderedByZIndex=false] - If set to true, it will return the {@link CB_GraphicSprites} objects sorted by their z-index (ascending order).
600 * @param {*} [returnValueOnFail=undefined] - The value we want it to return in the case that no value is found. If not provided, undefined will be returned.
601 * @returns {array|*} Returns an array with all the {@link CB_GraphicSprites} objects or the value of "returnValueOnFail" otherwise.
602 */
603CB_GraphicSpritesScene.prototype.getGraphicSpritesAll = CB_GraphicSpritesScene.prototype.getAll = function(orderedByZIndex, returnValueOnFail)
604{
605 if (this.spritesGroups)
606 {
607 if (!orderedByZIndex)
608 {
609 return (this.spritesGroups.items) ? this.spritesGroups.items : returnValueOnFail;
610 }
611 else
612 {
613 return (this.spritesGroups.itemsByZIndex) ? this.spritesGroups.itemsByZIndex : returnValueOnFail;
614 }
615 }
616 return returnValueOnFail;
617}
618
619
620/**
621 * Alias for {@link CB_GraphicSpritesScene#getGraphicSprites}.
622 * @function CB_GraphicSpritesScene#get
623 * @see {@link CB_GraphicSpritesScene#getGraphicSprites}
624 */
625/**
626 * Gets a desired {@link CB_GraphicSprites} object through its index (its position in the {@link CB_GraphicSpritesScene#spritesGroups.items} array). Faster than getting it through its identifier with the {@link CB_GraphicSpritesScene#getGraphicSpritesById} method.
627 * @function
628 * @param {integer} [index=0] - The index where the desired {@link CB_GraphicSprites} object must be located (its position in the {@link CB_GraphicSpritesScene#spritesGroups.items} array).
629 * @param {*} [returnValueOnFail=undefined] - The value we want it to return in the case that no value is found. If not provided, undefined will be returned.
630 * @returns {CB_GraphicSprites|*} Returns a {@link CB_GraphicSprites} object if found or the value of "returnValueOnFail" otherwise.
631 */
632CB_GraphicSpritesScene.prototype.getGraphicSprites = CB_GraphicSpritesScene.prototype.get = function(index, returnValueOnFail)
633{
634 index = parseInt(index);
635 index = isNaN(index) ? 0 : index;
636 if (index &lt; 0) { index *= -1; } //It must be a positive integer.
637 return this.spritesGroups &amp;&amp; this.spritesGroups.items &amp;&amp; this.spritesGroups.items[index] ? this.spritesGroups.items[index] : returnValueOnFail;
638}
639
640
641/**
642 * Alias for {@link CB_GraphicSpritesScene#getGraphicSpritesById}.
643 * @function CB_GraphicSpritesScene#getById
644 * @see {@link CB_GraphicSpritesScene#getGraphicSpritesById}
645 */
646/**
647 * Gets a desired {@link CB_GraphicSprites} object through its identifier. Slower than getting it through its index with the {@link CB_GraphicSpritesScene#getGraphicSprites} method.
648 * @function
649 * @param {string|*} [id=undefined] - The identifier of the {@link CB_GraphicSprites} object that we want to get.
650 * @param {*} [returnValueOnFail=undefined] - The value we want it to return in the case that no value is found. If not provided, undefined will be returned.
651 * @returns {CB_GraphicSprites|*} Returns a {@link CB_GraphicSprites} object if found or the value of "returnValueOnFail" otherwise.
652 */
653CB_GraphicSpritesScene.prototype.getGraphicSpritesById = CB_GraphicSpritesScene.prototype.getById = function(id, returnValueOnFail)
654{
655 var index = this.getGraphicSpritesIndexById(id);
656 return index !== -1 ? this.spritesGroups.items[index] : returnValueOnFail;
657}
658
659
660/**
661 * Alias for {@link CB_GraphicSpritesScene#getGraphicSpritesIndexById}.
662 * @function CB_GraphicSpritesScene#getIndexById
663 * @see {@link CB_GraphicSpritesScene#getGraphicSpritesIndexById}
664 */
665/**
666 * Gets the index (the position in the {@link CB_GraphicSpritesScene#spritesGroups.items} array) of a desired {@link CB_GraphicSprites} object by its identifier.
667 * @function
668 * @param {string|*} [id=undefined] - The identifier of the {@link CB_GraphicSprites} object whose index we want to get.
669 * @returns {integer} Returns the index (the position in the {@link CB_GraphicSpritesScene#spritesGroups.items} array) of the desired {@link CB_GraphicSprites} object or -1 if not found.
670 * @todo Optimize it (perhaps using a cache matching the IDs with their position, maybe using the "position" or "positionByZIndex" properties).
671 */
672CB_GraphicSpritesScene.prototype.getGraphicSpritesIndexById = CB_GraphicSpritesScene.prototype.getIndexById = function(id)
673{
674 if (this.spritesGroups &amp;&amp; this.spritesGroups.items)
675 {
676 var spritesGroupsLength = this.spritesGroups.items.length;
677 for (var x = 0; x &lt; spritesGroupsLength; x++)
678 {
679 if (this.spritesGroups.items[x].id === id) { return x; }
680 }
681 }
682 return -1;
683}
684
685
686/**
687 * Alias for {@link CB_GraphicSpritesScene#executeFunctionAll}.
688 * @function CB_GraphicSpritesScene#executeAll
689 * @see {@link CB_GraphicSpritesScene#executeFunctionAll}
690 */
691 /**
692 * Alias for {@link CB_GraphicSpritesScene#executeFunctionAll}.
693 * @function CB_GraphicSpritesScene#forEach
694 * @see {@link CB_GraphicSpritesScene#executeFunctionAll}
695 */
696 /**
697 * Alias for {@link CB_GraphicSpritesScene#executeFunctionAll}.
698 * @function CB_GraphicSpritesScene#forEachGraphicSprites
699 * @see {@link CB_GraphicSpritesScene#executeFunctionAll}
700 */
701 /**
702 * Performs a desired action, using the provided function, on all the existing {@link CB_GraphicSprites} objects or on the desired ones (if provided). Calls the {@link CB_Arrays.executeFunctionAll} function internally and returns its returning value.
703 * @function
704 * @param {CB_Arrays.executeFunctionAll_ON_LOOP_CALLBACK} functionEach - Function that will be called for each {@link CB_GraphicSprites} object. As the first parameter it receives the {@link CB_GraphicSprites} object of the "graphicSpritesObjects" being looped, as the second parameter the position of this {@link CB_GraphicSprites} object in the "graphicSpritesObjects" array provided (or, if not provided, in the array returned by the {@link CB_GraphicSpritesScene#getGraphicSpritesAll} method), the third parameter is the array being looped and the fourth parameter will be the "delayBetweenEach" being used, being "this" the {@link CB_GraphicSprites} object itself.
705 * @param {boolean} [orderedByZIndex=false] - If set to true, it will loop the {@link CB_GraphicSprites} sorted by their z-index (ascending order).
706 * @param {number|CB_Arrays.executeFunctionAll_ON_LOOP_CALLBACK} [delayBetweenEach=0] - If a value greater than zero is used, it will be used as the delay desired between each call to the "functionEach" function (calling them using the [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} function internally). If not provided or the value is 0 (zero) or lower, each call to the "functionEach" function will be performed immediately one after the other. If a function is provided, it will be called with the same parameters as the "functionEach" function and its returning value will be used as the delay (executed every loop for each {@link CB_GraphicSprites} object).
707 * @param {array} [graphicSpritesObjects={@link CB_GraphicSpritesScene#getGraphicSpritesAll}()] - A numeric array containing the {@link CB_GraphicSprites} objects that we want to loop. It should contain only {@link CB_GraphicSprites} objects which are already in the current {@link CB_GraphicSpritesScene} object. If not provided, it will use all the {@link CB_GraphicSprites} objects contained in the {@link CB_GraphicSpritesScene} object.
708 * @param {boolean} [returnSetTimeoutsArray=false] - Defines whether we want the method to return an integer or a numeric array with information of each [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} call. Returning an array with information of each [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} call is only useful when the [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} function is called internally, which happens when the "delayBetweenEach" parameter is greater than 0 (zero).
709 * @param {boolean} [delayBetweenEachAffectsFirst=false] - If set to true, the desired delay (if any) will also affect the first call to the "functionEach" function.
710 * @param {CB_Arrays.executeFunctionAll_ON_FINISH_CALLBACK} [functionFinish] - Function that will be called for when it has finished looping all the items. The first parameter will be the array which was looped, the second parameter will be the number of times that the "functionEach" callback was called (the most likely, matches the number of elements unless they are undefined or null), and the third parameter will be the maximum "delay" used, being "this" the array itself.
711 * @returns {integer|array} If the "returnSetTimeoutsArray" parameter is set to false, it will return the number of calls to the "functionEach" function that were performed (which should be the same number as the {@link CB_GraphicSprites} objects given in the "graphicSpritesObjects" parameter). Otherwise, if the "returnSetTimeoutsArray" is set to true, it will return a numeric array with a {@link CB_Arrays.executeFunctionAll_OBJECT} object for each {@link CB_GraphicSprites} given. The length of this array will also be the number of calls to the "functionEach" function that were performed. Note that if a value greater than 0 (zero) for the "delayBetweenEach" parameter has been provided, perhaps not all calls of the "functionEach" function will have been performed yet when exiting this method because of the asynchronous nature of the [setTimeout]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout} function.
712 * @todo Think about only allowing {@link CB_GraphicSprites} objects (in the "graphicSpritesObjects" parameter) which are already in the {@link CB_GraphicSpritesScene} (identify them by their ID), to avoid problems.
713 */
714CB_GraphicSpritesScene.prototype.executeFunctionAll = CB_GraphicSpritesScene.prototype.executeAll = CB_GraphicSpritesScene.prototype.forEachGraphicSprites = CB_GraphicSpritesScene.prototype.forEach = function(functionEach, orderedByZIndex, delayBetweenEach, graphicSpritesObjects, returnSetTimeoutsArray, delayBetweenEachAffectsFirst, functionFinish)
715{
716 return CB_Arrays.executeFunctionAll(CB_isArray(graphicSpritesObjects) ? graphicSpritesObjects : this.getGraphicSpritesAll(orderedByZIndex, []), functionEach, delayBetweenEach, returnSetTimeoutsArray, delayBetweenEachAffectsFirst, functionFinish);
717}
718
719
720/**
721 * Sets the desired value of a given property name to the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object as well to its {@link CB_GraphicSprites} objects and their children (their {@link CB_GraphicSprites.SPRITES_OBJECT} object, including their {@link CB_GraphicSprites.SPRITE_OBJECT} and their {@link CB_GraphicSprites.SUBSPRITE_OBJECT} objects). Calls the {@link CB_GraphicSprites#setPropertyCascade} method internally.
722 * @function
723 * @param {number} propertyName - The name of the property we want to affect. Also used as the "propertyName" parameter when calling the {@link CB_GraphicSprites#setPropertyCascade} method internally.
724 * @param {*} [value=undefined] - The value desired for the given property. Also used as the "value" parameter when calling the {@link CB_GraphicSprites#setPropertyCascade} method internally.
725 * @param {boolean} [onlyCurrent=false] - If set to true, it will only affect the current sprite and its sub-sprites of each {@link CB_GraphicSprites} object (and also the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object and the {@link CB_GraphicSprites.SPRITES_OBJECT} object of each {@link CB_GraphicSprites} object). Used as the "propertyName" parameter when calling the {@link CB_GraphicSprites#setPropertyCascade} method internally.
726 * @returns {integer} Returns the number of elements affected (counting the {@link CB_GraphicSpritesScene.SPRITES_GROUPS_OBJECT} object and the {@link CB_GraphicSprites.SPRITES_OBJECT} objects).
727 */
728CB_GraphicSpritesScene.prototype.setPropertyCascade = function(propertyName, value, onlyCurrent)
729{
730 if (!propertyName) { return; }
731
732 this.spritesGroups[propertyName] = value;
733 var affected = 1;
734
735 this.forEachGraphicSprites(function() { affected += this.setPropertyCascade(propertyName, value, onlyCurrent); });
736
737 return affected;
738}
739
740
741/**
742 * Gets a new copy of this object with the same attributes (all sub-objects will be a copy, they will not the same reference).
743 * @function
744 * @param {boolean} [avoidCopyingPointers=false] - If set to true, it will not copy the {@link CB_GraphicSprites#pointer} property of each {@link CB_GraphicSprites} object.
745 * @param {boolean} [avoidCopyingTimes=false] - If set to true, it will not copy neither the {@link CB_GraphicSprites#time} property of each {@link CB_GraphicSprites} object nor the "time" property of each of their sprites ({@link CB_GraphicSprites.SPRITE_OBJECT} objects).
746 * @param {boolean} [clearReferences=false] - If set to true, it will not copy neither the "container" nor the "parent" nor the "data.that" nor the "data.getThis" properties of any element. Useful to be able to stringify the object preventing the "TypeError: cyclic object value" error. When set to true, calls the {@link CB_GraphicSprites.clearReferences} function internally. If set to true and the "filterProperties" parameter is also set to true, the {@link CB_GraphicSprites.filterProperties} will always be called before calling the {@link CB_GraphicSprites.clearReferences} function.
747 * @param {boolean} [filterProperties=false] - If set to true, it will call the {@link CB_GraphicSprites.filterProperties} function internally to filter the properties that we do not want to keep (using the given "propertiesToKeepObject" as the parameter to call it). When set to true, calls the {@link CB_GraphicSprites.filterProperties} function internally. If set to true and the "clearReferences" parameter is also set to true, the {@link CB_GraphicSprites.filterProperties} will always be called before calling the {@link CB_GraphicSprites.clearReferences} function.
748 * @param {CB_GraphicSprites.filterProperties_propertiesToKeepObject_TYPE} [propertiesToKeepObject=CB_GraphicSprites.filterProperties_DEFAULT_PROPERTIES] - The object with the properties that we want to keep. Only used when the "filterProperties" parameter is set to true, as the "propertiesToKeepObject" when calling the {@link CB_GraphicSprites.filterProperties} function internally.
749 * @returns {CB_GraphicSpritesScene} Returns a copy of this object with the same attributes (all sub-objects will be a copy, not the same reference).
750 */
751CB_GraphicSpritesScene.prototype.getCopy = function(avoidCopyingPointers, avoidCopyingTimes, clearReferences, filterProperties, propertiesToKeepObject)
752{
753 var spritesGroupsCopy = CB_copyObject(this.spritesGroups);
754
755 var newCopy = new CB_GraphicSpritesScene(spritesGroupsCopy, false);
756
757 CB_GraphicSprites._copyNeededProperties(newCopy, this) //Copies the needed properties from the original element.
758 CB_GraphicSprites._copyNeededProperties(newCopy.spritesGroups, this.spritesGroups) //Copies the needed properties from the original element.
759
760 this.forEach
761 (
762 function(CB_GraphicSpritesObject, index)
763 {
764 CB_GraphicSprites._copyNeededProperties(newCopy.get(index), CB_GraphicSpritesObject) //Copies the needed properties from the original element.
765 CB_GraphicSprites._copyNeededProperties(newCopy.get(index).spritesGroup, CB_GraphicSpritesObject.spritesGroup) //Copies the needed properties from the original element.
766
767 //If desired, sets the same pointers of each CB_GraphicSprites object:
768 if (!avoidCopyingPointers) { newCopy.get(index).pointer = this.pointer; newCopy.get(index).pointerPrevious = this.pointerPrevious; }
769 if (!avoidCopyingTimes) { newCopy.get(index).time = this.time; }
770 newCopy.get(index).time = this.time;
771 this.forEach
772 (
773 function(sprite, spriteIndex)
774 {
775 if (!avoidCopyingTimes) { newCopy.get(index).get(spriteIndex).time = this.time; }
776
777 CB_GraphicSprites._copyNeededProperties(newCopy.get(index).get(spriteIndex), sprite) //Copies the needed properties from the original element.
778
779 sprite.forEach
780 (
781 function(subSprite, subSpriteIndex)
782 {
783 CB_GraphicSprites._copyNeededProperties(newCopy.get(index).get(spriteIndex).get(subSpriteIndex), subSprite) //Copies the needed properties from the original element.
784
785 //If desired, sets the same times:
786 if (!avoidCopyingTimes) { sprite.get(subSpriteIndex).time = this.time; }
787 }
788 );
789 }
790 );
791 }
792 );
793
794 //Sets the same parent:
795 newCopy.parent = this.parent;
796
797 //If we want to, filters the properties keeping just the desired ones:
798 if (filterProperties) { newCopy = CB_GraphicSprites.filterProperties(newCopy, propertiesToKeepObject); }
799
800 //If we want to, clears the references:
801 if (clearReferences) { CB_GraphicSprites.clearReferences(newCopy); }
802
803 return newCopy;
804}</pre>
805 </article>
806</section>
807
808
809
810
811
812 </div>
813 </div>
814
815 <div class="clearfix"></div>
816
817
818
819</div>
820</div>
821
822
823 <div class="modal fade" id="searchResults">
824 <div class="modal-dialog">
825 <div class="modal-content">
826 <div class="modal-header">
827 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
828 <h4 class="modal-title">Search results</h4>
829 </div>
830 <div class="modal-body"></div>
831 <div class="modal-footer">
832 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
833 </div>
834 </div><!-- /.modal-content -->
835 </div><!-- /.modal-dialog -->
836 </div>
837
838
839<footer>
840
841
842 <span class="copyright">
843 <a href="printable/" target="_blank">See a more printer-friendly version</a><hr /><span style="color:#000000">© <address style="display:inline; font-style:normal;"><a href="https://crossbrowdy.com/" target="_blank">CrossBrowdy</a> API documentation</address> by <a href="https://joanalbamaldonado.com/" target="_blank">Joan Alba Maldonado</a> - <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International</a><br />DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.</span>
844 </span>
845
846<span class="jsdoc-message">
847 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
848
849 on Mon Feb 3rd 2020
850
851 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
852</span>
853</footer>
854
855<script src="scripts/docstrap.lib.js"></script>
856<script src="scripts/toc.js"></script>
857
858 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
859
860
861<script>
862$( function () {
863 $( "[id*='$']" ).each( function () {
864 var $this = $( this );
865
866 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
867 } );
868
869 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
870 var $this = $( this );
871
872 var example = $this.find( "code" );
873 exampleText = example.html();
874 var lang = /{@lang (.*?)}/.exec( exampleText );
875 if ( lang && lang[1] ) {
876 exampleText = exampleText.replace( lang[0], "" );
877 example.html( exampleText );
878 lang = lang[1];
879 } else {
880 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
881 lang = langClassMatch ? langClassMatch[1] : "javascript";
882 }
883
884 if ( lang ) {
885
886 $this
887 .addClass( "sunlight-highlight-" + lang )
888 .addClass( "linenums" )
889 .html( example.html() );
890
891 }
892 } );
893
894 Sunlight.highlightAll( {
895 lineNumbers : true,
896 showMenu : true,
897 enableDoclinks : true
898 } );
899
900 $.catchAnchorLinks( {
901 navbarOffset: 10
902 } );
903 $( "#toc" ).toc( {
904 anchorName : function ( i, heading, prefix ) {
905 return $( heading ).attr( "id" ) || ( prefix + i );
906 },
907 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
908 showAndHide : false,
909 smoothScrolling: true
910 } );
911
912 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
913 $( '.dropdown-toggle' ).dropdown();
914
915 $( "table" ).each( function () {
916 var $this = $( this );
917 $this.addClass('table');
918 } );
919
920} );
921</script>
922
923
924
925<!--Navigation and Symbol Display-->
926
927<script>
928 $( function () {
929 $( '#main' ).localScroll( {
930 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
931 } );
932 $( "dt.name" ).each( function () {
933 var $this = $( this ).find("h4");
934 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
935 var dt = $(this);
936 var children = dt.next( "dd" );
937
938 dt.prepend( icon ).css( {cursor : "pointer"} );
939 dt.addClass( "member-collapsed" ).addClass( "member" );
940
941
942 children.hide();
943
944 dt.children().on( "click", function () {
945 children = dt.next( "dd" );
946 children.slideToggle( "fast", function () {
947
948 if ( children.is( ":visible" ) ) {
949 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
950 dt.addClass( "member-open" ).animate( "member-collapsed" );
951 } else {
952 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
953 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
954 }
955 } );
956 } );
957
958 } );
959 } );
960</script>
961
962
963<!--Google Analytics-->
964
965
966
967 <script type="text/javascript">
968 $(document).ready(function() {
969 SearcherDisplay.init();
970 });
971 </script>
972
973
974</body>
975</html>