terebentina Posted May 15, 2015 Share Posted May 15, 2015 Hi, I was wondering if there's any way to access a texture that was already loaded via PIXI.loader by its given resource name. The reason for this is because I'd prefer not to use the path to the image all over my code, in case I change that.So if I load a resource like {name: 'foo', url: 'assets/img/foo.png'} I would like to then usePIXI.Sprite.fromName('foo');instead of PIXI.Sprite.fromImage('assets/img/foo.png');I know there's no "fromName" method in Sprite but is something like this doable without having access to the original resource object returned by the loader in the load() method? Quote Link to comment Share on other sites More sharing options...
xdiepx Posted May 15, 2015 Share Posted May 15, 2015 I did something like this (when the load has completed). var MyFooImage = new PIXI.Sprite(resources.foo.texture);then add it to your container. Quote Link to comment Share on other sites More sharing options...
xerver Posted May 15, 2015 Share Posted May 15, 2015 When the loader completes all the resources it loaded are in `PIXI.loader.resources`, it also passes the resources to the complete callback you register:PIXI.loader.add('key', 'someImage.png').load(function (loader, resources) { // this will log "true", they are all the same: console.log(PIXI.loader.resources === loader.resources === resources); // resources is an object keyed by your names, you can get the loaded // texture like: console.log(resources.key.texture);}); Quote Link to comment Share on other sites More sharing options...
benunca Posted November 25, 2015 Share Posted November 25, 2015 I see false returned from this.PIXI.loader.add('key', 'someImage.png').load(function (loader, resources) { // this will log "true", they are all the same: console.log(PIXI.loader.resources === loader.resources === resources); // resources is an object keyed by your names, you can get the loaded // texture like: console.log(resources.key.texture);});Also, PIXI.loader is comming back undefined ... any clue what the issue might be? I'm a PIXI noob, but am rather far along with Javascript, so this is kind of baffling. Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 26, 2015 Share Posted November 26, 2015 @benunca, you're definitely using Pixi v3? Quote Link to comment Share on other sites More sharing options...
benunca Posted November 30, 2015 Share Posted November 30, 2015 Pixi.js 3.0.7 - ✰ WebGL ✰ http://www.pixijs.com/ ♥♥♥ Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 30, 2015 Share Posted November 30, 2015 hmm, dont know what to suggest, other than version (which is fine), you're not using any funky module loader that hides `PIXI` from global?<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/3.0.8/pixi.min.js"></script>// log output> PIXI< Object {VERSION: "3.0.8", PI_2: 6.283185307179586, RAD_TO_DEG: 57.29577951308232, DEG_TO_RAD: 0.017453292519943295, TARGET_FPMS: 0.06…}> PIXI.loader< f {baseUrl: "", progress: 0, loading: false, _progressChunk: 0, _beforeMiddleware: Array[0]…}Although, thinking about it, you cant have `false` returned, if `PIXI.loader` is undefined it would throw when you try to call a method on an undefined type. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.