MCPcopy Create free account
hub / github.com/melonjs/melonJS / constructor

Method constructor

packages/melonjs/src/renderable/entity/entity.js:181–265  ·  view source on GitHub ↗

* @param {number} x - the x coordinates of the entity object * @param {number} y - the y coordinates of the entity object * @param {object} settings - Entity properties, to be defined through Tiled or when calling the entity constructor * * @pa

(x, y, settings)

Source from the content-addressed store, hash-verified

179 * @deprecated since 18.1.0 — see the class-level documentation for migration examples
180 */
181 constructor(x, y, settings) {
182 // deprecation warning (once per session)
183 if (!Entity._deprecationWarned) {
184 warning("me.Entity", "me.Sprite combined with me.Body", "18.1.0");
185 Entity._deprecationWarned = true;
186 }
187
188 // call the super constructor
189 super(x, y, settings.width, settings.height);
190
191 /**
192 * The array of renderable children of this entity.
193 * @ignore
194 */
195 this.children = [];
196
197 if (settings.image) {
198 // set the frame size to the given entity size, if not defined in settings
199 settings.framewidth = settings.framewidth || settings.width;
200 settings.frameheight = settings.frameheight || settings.height;
201 this.renderable = new Sprite(0, 0, settings);
202 }
203
204 // Update anchorPoint
205 if (settings.anchorPoint) {
206 this.anchorPoint.setMuted(settings.anchorPoint.x, settings.anchorPoint.y);
207 } else {
208 // for backward compatibility
209 this.anchorPoint.setMuted(0, 0);
210 }
211
212 // set the sprite name if specified
213 if (typeof settings.name === "string") {
214 this.name = settings.name;
215 }
216
217 /**
218 * object type (as defined in Tiled)
219 * @type {string}
220 */
221 this.type = settings.type || "";
222
223 /**
224 * object unique ID (as defined in Tiled)
225 * @type {number}
226 */
227 this.id = settings.id || "";
228
229 /**
230 * dead/living state of the entity<br>
231 * default value : true
232 * @type {boolean}
233 */
234 this.alive = true;
235
236 // initialize the default body
237 if (typeof settings.shapes === "undefined") {
238 settings.shapes = polygonPool.get(0, 0, [

Callers

nothing calls this directly

Calls 8

onBodyUpdateMethod · 0.95
warningFunction · 0.90
setMutedMethod · 0.65
getMethod · 0.65
getBoundsMethod · 0.65
setCollisionMaskMethod · 0.65
setCollisionTypeMethod · 0.65
resizeMethod · 0.45

Tested by

no test coverage detected