Skip to content

Commit a682b83

Browse files
committed
BitmapText.getCharacterAt is a new method that will return the character data from the BitmapText at the given x and y corodinates. The character data includes the code, position, dimensions and glyph information.
1 parent a72fdd4 commit a682b83

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,35 +387,29 @@ var BitmapText = new Class({
387387
* Gets the character located at the given x/y coordinate within this Bitmap Text.
388388
*
389389
* The coordinates you pass in are translated into the local space of the
390-
* Bitmap Text, however, it is up to you to first translate the input coordinates.
390+
* Bitmap Text, however, it is up to you to first translate the input coordinates to world space.
391391
*
392392
* If you wish to use this in combination with an input event, be sure
393-
* to pass in `Pointer.worldX` and `worldY` so they are transformed into
394-
* camera space.
393+
* to pass in `Pointer.worldX` and `worldY` so they are in world space.
395394
*
396395
* In some cases, based on kerning, characters can overlap. When this happens,
397396
* the first character in the word is returned.
398397
*
398+
* Note that this does not work for DynamicBitmapText if you have changed the
399+
* character positions during render. It will only scan characters in their un-translated state.
400+
*
399401
* @method Phaser.GameObjects.BitmapText#getCharacterAt
400402
* @since 3.25.0
401403
*
402404
* @param {number} x - The x position to check.
403405
* @param {number} y - The y position to check.
404406
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera which is being tested against. If not given will use the Scene default camera.
405407
*
406-
* @return {Phaser.Types.GameObjects.BitmapText.BitmapTextCharacter} The character at the given position, or `null`.
408+
* @return {Phaser.Types.GameObjects.BitmapText.BitmapTextCharacter} The character object at the given position, or `null`.
407409
*/
408410
getCharacterAt: function (x, y, camera)
409411
{
410-
if (camera === undefined) { camera = this.scene.sys.cameras.main; }
411-
412-
var csx = camera.scrollX;
413-
var csy = camera.scrollY;
414-
415-
var px = x + (csx * this.scrollFactorX) - csx;
416-
var py = y + (csy * this.scrollFactorY) - csy;
417-
418-
var point = this.getWorldTransformMatrix().applyInverse(px, py);
412+
var point = this.getLocalPoint(x, y, null, camera);
419413

420414
var bounds = this.getTextBounds(true);
421415

@@ -785,9 +779,9 @@ BitmapText.ParseFromAtlas = ParseFromAtlas;
785779
* @since 3.17.0
786780
*
787781
* @param {XMLDocument} xml - The XML Document to parse the font from.
782+
* @param {Phaser.Textures.Frame} frame - The texture frame to take into account when creating the uv data.
788783
* @param {integer} [xSpacing=0] - The x-axis spacing to add between each letter.
789784
* @param {integer} [ySpacing=0] - The y-axis spacing to add to the line height.
790-
* @param {Phaser.Textures.Frame} [frame] - The texture frame to take into account while parsing.
791785
*
792786
* @return {Phaser.Types.GameObjects.BitmapText.BitmapFontData} The parsed Bitmap Font data.
793787
*/

0 commit comments

Comments
 (0)