Flake Posted June 4, 2015 Share Posted June 4, 2015 Hello! I've got a question about the v3 assetloader/resourceloader:After loading an asset like such:var loader = PIXI.loader;loader.add('img',"assets/image.jpg");.. can I access the resource with (what I assume is ) the key? Edit: posted it wrong the first time In other words? Is there a way to do this:var sprite = PIXI.Sprite.fromFrame("img");..instead of what I'm doing currently:var sprite = PIXI.Sprite.fromFrame("assets/image.jpg");appreciated as always! Quote Link to comment Share on other sites More sharing options...
xerver Posted June 4, 2015 Share Posted June 4, 2015 That is really confusing, because `'img'` is the key but in your example you say you are already using the key... That is extra confusing because using the key in the fromX() convience methods doesn't work... If you want to use the loader, just use the loader: http://www.html5gamedevs.com/topic/14524-v3-access-cached-texture-by-name/?p=82661PIXI.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...
d13 Posted June 4, 2015 Share Posted June 4, 2015 I might be mis-interpreting your question (very possible!), but... Do you just want to load an image and reference its texture using it's file path name?You can do that like this:PIXI.loader .add("assets/image.jpg") .load(setup);(The `key` in Pixi's loader `add` method is optional - all you need is the URL.)Then, after the image has loaded, create the sprite like this:function setup() { var sprite = new PIXI.Sprite.fromImage("assets/image.jpg");} Quote Link to comment Share on other sites More sharing options...
Flake Posted June 4, 2015 Author Share Posted June 4, 2015 Thanks @xerver & @d13! Sorry, I switched the code snippets by mistake . But you guys rocked it anyway, I think I've got it.Just to clarify; I was looking for a less verbose way of accessing the resources after loading them. It appears that these are the shortest ways of doing it:new PIXI.Sprite.fromImage("assets/image.jpg"); //ornew PIXI.Sprite(PIXI.loader.resources["assetKey"].texture); //ornew PIXI.Sprite(resources["assetKey"].texture); // through "var resource = PIXI.loader.resource"cheers Quote Link to comment Share on other sites More sharing options...
d13 Posted June 5, 2015 Share Posted June 5, 2015 I was looking for a less verbose way of accessing the resources after loading them. I'm always looking for that too!Hopefull Pixi v.4 will implement something like this: `var sprite = new PIXI.Sprite("assets/image.jpg")`... and figure out the texture, key, or frame based on the context. 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.