MCPcopy Index your code
hub / github.com/KilledByAPixel/LittleJS / updateTransforms

Method updateTransforms

src/engineObject.js:130–152  ·  view source on GitHub ↗

Update the object transform, called automatically by engine even when paused

()

Source from the content-addressed store, hash-verified

128
129 /** Update the object transform, called automatically by engine even when paused */
130 updateTransforms()
131 {
132 const parent = this.parent;
133 if (parent)
134 {
135 // compose with parent transform inline to avoid intermediate vector allocs
136 const mirror = parent.getMirrorSign();
137 const lp = this.localPos, pp = parent.pos;
138 const lx = lp.x*mirror, ly = lp.y, pa = parent.angle;
139 if (pa)
140 {
141 const c = cos(-pa), s = sin(-pa);
142 this.pos = new Vector2(lx*c - ly*s + pp.x, lx*s + ly*c + pp.y);
143 }
144 else
145 this.pos = new Vector2(lx + pp.x, ly + pp.y);
146 this.angle = mirror*this.localAngle + pa;
147 }
148
149 // update children
150 for (const child of this.children)
151 child.updateTransforms();
152 }
153
154 /** Update the object physics, called automatically by engine once each frame. Can be overridden to stop or change how physics works for an object. */
155 updatePhysics()

Callers 4

smoke.test.mjsFile · 0.45
engineUpdateFunction · 0.45
engineObjectsUpdateFunction · 0.45
addChildMethod · 0.45

Calls 1

getMirrorSignMethod · 0.80

Tested by

no test coverage detected