Accessing cached image info

So say in my scene, I have something like

this.load.image('myKey', 'assets/sprites/temp-whatever.png');

Previously in Phaser 2, you could later access the image’s info (eg, width, height etc), via the game.cache.getKey('myKey'); but that equivalent functionality doesn’t seem to exist anymore.

I checked out the docs and while there’s still a game.cache, I don’t see any getKey and none of the sub-objects (such as audio, binary) appeared to be empty, Unless I’m looking in the wrong place?

They are in this.textures (from a scene) now.

Thanks - appreciate that. Always obvious when yo know how/where :laughing:

Is there an example how that works?
I also need width and height, but seem to be unable to get them.

I tried
this.textures[‘key’].width

var tex = this.textures.get(‘key’);

I think you need to use getSourceImage(), and work with that (for your other topic, and call it only once, not in the process callback).

2 Likes

That has worked, thanks.

var tex = this.textures.get(‘key’).getSourceImage();

I created a test output that shows the correct values now:
Textx.setText('width: ’ + tex.width);
Texty.setText('height: ’ + tex.height);

You do know you can just use console.log(tex); ? :slight_smile:

yes, but I just had those text fields ready :wink: