Skip to content

Commit 6d83cae

Browse files
committed
The Texture class has a new method getDataSourceImage which will return the raw image data of the data source.
1 parent b0c853a commit 6d83cae

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The Loader has been given an overhaul to improve its performance and extensibili
6565
* All Game Object Creators now have an extra boolean argument `addToScene`. If you set this to `true` it will add the Game Object being created to the Scene automatically, while `false` will do the opposite, i.e.: `this.make.image(config, false)`. You can still specify the `add` property in the Config object too, but if the argument is provided it will override the property.
6666
* We have removed the TextureManager.addAtlasPyxel method and related parser. It didn't work anyway and no-one seems to use Pyxel any more. If we get enough demand we can consider adding it back.
6767
* When adding an Audio Sprite to the Sound Manager it will now respect the `loop` property, if set in the source JSON.
68+
* The Texture class has a new method `getDataSourceImage` which will return the raw image data of the data source.
6869

6970
### Bug Fixes
7071

src/textures/Texture.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,43 @@ var Texture = new Class({
334334
}
335335
},
336336

337+
/**
338+
* Given a Frame name, return the data source image it uses to render with.
339+
* You can use this to get the normal map for an image for example.
340+
*
341+
* This will return the actual DOM Image.
342+
*
343+
* @method Phaser.Textures.Texture#getDataSourceImage
344+
* @since 3.7.0
345+
*
346+
* @param {(string|integer)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture.
347+
*
348+
* @return {(HTMLImageElement|HTMLCanvasElement)} The DOM Image or Canvas Element.
349+
*/
350+
getDataSourceImage: function (name)
351+
{
352+
if (name === undefined || name === null || this.frameTotal === 1)
353+
{
354+
name = '__BASE';
355+
}
356+
357+
var frame = this.frames[name];
358+
var idx;
359+
360+
if (!frame)
361+
{
362+
console.warn('No Texture.frame found with name ' + name);
363+
364+
idx = this.frames['__BASE'].sourceIndex;
365+
}
366+
else
367+
{
368+
idx = frame.sourceIndex;
369+
}
370+
371+
return this.dataSource[idx].image;
372+
},
373+
337374
/**
338375
* Adds a data source image to this Texture.
339376
*

0 commit comments

Comments
 (0)