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

Method updateBounds

packages/melonjs/src/renderable/text/bitmaptext.js:254–300  ·  view source on GitHub ↗

* update the bounding box for this Bitmap Text. * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates * @returns {Bounds} this Bitmap Text bounding box Rectangle object

(absolute = true)

Source from the content-addressed store, hash-verified

252 * @returns {Bounds} this Bitmap Text bounding box Rectangle object
253 */
254 updateBounds(absolute = true) {
255 const bounds = this.getBounds();
256
257 bounds.clear();
258
259 if (typeof this.metrics !== "undefined") {
260 const w = this.metrics.width;
261 const h = this.metrics.height;
262
263 // compute x offset based on textAlign
264 let ax = 0;
265 switch (this.textAlign) {
266 case "right":
267 ax = w;
268 break;
269 case "center":
270 ax = w / 2;
271 break;
272 }
273
274 // baseline shift based on total text height (matching draw code)
275 const gy = this.metrics.glyphYOffset || 0;
276 let ay = 0;
277 switch (this.textBaseline) {
278 case "middle":
279 ay = gy + h * 0.5;
280 break;
281 case "ideographic":
282 case "alphabetic":
283 case "bottom":
284 ay = gy + h;
285 break;
286 }
287
288 bounds.addFrame(-ax, -ay + gy, w - ax, -ay + gy + h);
289 }
290
291 if (absolute === true) {
292 const absPos = this.getAbsolutePosition();
293 bounds.centerOn(
294 absPos.x + bounds.x + bounds.width / 2,
295 absPos.y + bounds.y + bounds.height / 2,
296 );
297 }
298
299 return bounds;
300 }
301
302 /**
303 * defines the color used to tint the bitmap text

Callers 2

setTextMethod · 0.95
resizeMethod · 0.95

Calls 5

addFrameMethod · 0.80
getBoundsMethod · 0.65
clearMethod · 0.65
getAbsolutePositionMethod · 0.65
centerOnMethod · 0.45

Tested by

no test coverage detected