Schoening Posted May 29, 2015 Share Posted May 29, 2015 I would like to change my code from this:var burger = new PIXI.Sprite( textures["burger"].texture );To this:var burger = new PIXI.Sprite( textures["burger"] );I thought that the easiest way of doing this would be to store the textures seperately from the parent object.var texturesOnly = {};var name = textures["burger"].name;var texture = textures["burger"].texture;texturesOnly[name] = texture;The most convienient place for this pseudo-code would be the loader.on("progress", cb); so that I can use the current loaded object and put it inside my custom texture object:loader.on("progress", onTextureLoadProgress);function onTextureLoadProgress () { var name = arguments[1]; var texture = arguments[1].texture; var texturesOnly[name] = texture;};But that code does not work!The texture is undefined. Also, what is the point of .on("complete" and .once("complete" if .load gets passed the resource object aswell ? I have read the manual pages and I am still none the wiser... Quote Link to comment Share on other sites More sharing options...
xerver Posted May 29, 2015 Share Posted May 29, 2015 There were a lot of questions here, let me try to break it down: I would like to change my code from this:var burger = new PIXI.Sprite( textures["burger"].texture );To this:var burger = new PIXI.Sprite( textures["burger"] );I thought that the easiest way of doing this would be to store the textures seperately from the parent object. I honestly can't imagine why this would be something you need to do, but it definitely can be done. var texturesOnly = {};var name = textures["burger"].name;var texture = textures["burger"].texture;texturesOnly[name] = texture;The most convienient place for this pseudo-code would be the loader.on("progress", cb); so that I can use the current loaded object and put it inside my custom texture object:loader.on("progress", onTextureLoadProgress);function onTextureLoadProgress () { var name = arguments[1]; var texture = arguments[1].texture; var texturesOnly[name] = texture;};But that code does not work!The texture is undefined. Correct, progress event is emitted before the middleware runs for an object. This has to do with progress values changing as more resources are added to the loader, which can happen in a middleware. Feel free to change this functionality in resource-loader if you want, as long as all the tests pass. Easier would be just on load parse the resources object into your cache structure, then just use it. Also, what is the point of .on("complete" and .once("complete" if .load gets passed the resource object aswell ? I have read the manual pages and I am still none the wiser...The `.load()` method accepts a callback. If you pass one (you don't have to) it just binds it to the 'complete' event for you. Everything is done via events, callback parameters are just sugar for them.The difference between `.on('complete', ...);` and `.once('complete', ...);` is that `.on()` is called each time an event is emitted, and `.once()` is only called a single time when the next instance of that event is emitted. You can read about the event API in EventEmitter3. You can listen to the 'complete' event yourself, or pass the load method a callack, they both operate exactly the same. Quote Link to comment Share on other sites More sharing options...
d13 Posted May 30, 2015 Share Posted May 30, 2015 Assuming your image file is called `images/burger.png`, you could just do something like this: var textures = PIXI.utils.TextureCache;var burger = new PIXI.Sprite(textures["images/burger.png"]); 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.