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

Method constructor

packages/melonjs/src/renderable/renderable.js:39–383  ·  view source on GitHub ↗

* @param {number} x - position of the renderable object (accessible through inherited pos.x property) * @param {number} y - position of the renderable object (accessible through inherited pos.y property) * @param {number} width - object width * @param {number} height - object height

(x, y, width, height)

Source from the content-addressed store, hash-verified

37 * @param {number} height - object height
38 */
39 constructor(x, y, width, height) {
40 // parent constructor
41 super(x, y, width, height);
42
43 /**
44 * Position of the Renderable relative to its parent container
45 * @public
46 * @type {ObservableVector3d}
47 */
48 this.pos = new ObservableVector3d(x, y, 0, () => {
49 this.updateBounds();
50 this.isDirty = true;
51 });
52
53 /**
54 * The anchor point is used for attachment behavior, and/or when applying transformations.<br>
55 * The coordinate system places the origin at the top left corner of the frame (0, 0) and (1, 1) means the bottom-right corner<br>
56 * <img src="images/anchor_point.png"/><br>
57 * a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
58 * <br>
59 * <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
60 * To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
61 * @type {ObservablePoint}
62 * @default <0.5,0.5>
63 */
64 this.anchorPoint = new ObservablePoint(0.5, 0.5, () => {
65 this.updateBounds();
66 this.isDirty = true;
67 });
68
69 if (typeof this.currentTransform === "undefined") {
70 /**
71 * the renderable transformation matrix (4x4).
72 * For standard 2D use, only the 2D components are used (rotate around Z, scale X/Y, translate X/Y).
73 * For 3D use (e.g. Mesh), the full 4x4 matrix supports rotation around any axis,
74 * 3D translation, and perspective projection.
75 * Use the `rotate()`, `scale()`, and `translate()` methods rather than modifying this directly.
76 * @type {Matrix3d}
77 */
78 this.currentTransform = new Matrix3d();
79 }
80 this.currentTransform.identity();
81
82 /**
83 * the renderable physics body — the handle returned by the
84 * active {@link PhysicsAdapter}'s `addBody` (or constructed
85 * imperatively via `new Body(...)`). Typed as the portable
86 * {@link PhysicsBody} interface; cast to the adapter-specific
87 * concrete type (`MatterAdapter.Body`, `BuiltinAdapter.Body`, or
88 * the legacy {@link Body} class) to reach native fields.
89 * @type {PhysicsBody}
90 * @example
91 * // define a new Player Class
92 * class PlayerEntity extends me.Sprite {
93 * // constructor
94 * constructor(x, y, settings) {
95 * // call the parent constructor
96 * super(x, y , settings);

Callers

nothing calls this directly

Calls 4

updateBoundsMethod · 0.95
setOpacityMethod · 0.95
getMethod · 0.65
identityMethod · 0.45

Tested by

no test coverage detected