pdiddles03 Posted July 28, 2015 Share Posted July 28, 2015 Should I create all the textures I need at the render of the game when it first starts or should i render them as I need them? I am not talking about preload, but the PIXI.Texture.fromImage type thing. If it is ok to render all of them it would solve a lot of issues for me. Quote Link to comment Share on other sites More sharing options...
bubamara Posted July 28, 2015 Share Posted July 28, 2015 PIXI.loader will automatically create all textures for you from loaded images. You just need to pick one from PIXI.loader.resources and you can use it whenever you want to 1st: preload imagesvar loader = PIXI.loader .add('image1', 'image1.png') .add('image2', 'image2.png') .once('complete', function(loader, resources) { init(); }) .load();2nd: use itfunction init() { var sprite1 = new PIXI.Sprite(PIXI.loader.resources.image1.texture); var sprite2 = new PIXI.Sprite(PIXI.loader.resources.image2.texture);} Rodrigo 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted July 29, 2015 Share Posted July 29, 2015 Or:PIXI.loader .add("images/textureOne.png") .add("images/textureTwo.png") .load(setup);function setup() { var spriteOne = PIXI.Sprite.fromImage("images/textureOne.png"); var spriteTwo = PIXI.Sprite.fromImage("images/textureTwo.png");} Quote Link to comment Share on other sites More sharing options...
xerver Posted July 29, 2015 Share Posted July 29, 2015 Or:PIXI.loader .add("images/textureOne.png") .add("images/textureTwo.png") .load(setup);function setup() { var spriteOne = PIXI.Sprite.fromImage("images/textureOne.png"); var spriteTwo = PIXI.Sprite.fromImage("images/textureTwo.png");} No! Please don't encourage people to mix the loader and convenience methods. I spend half my time on this forum explaining why they don't mix well and why code is often broken when you try to mix them. Just use the loader values if you are using the loader. If you don't want to preload and want to just create a sprite from arbitrary string urls, then use the convenience methods. DON'T MIX THEM PLEASE!! It only works under very specific circumstances and most of the time will be broken or duplicate objects in memory. The two APIs are not related, using the loader to warm the internal texture cache for use with those methods is a hack and should not be used in production code. The texture cache for convenience methods is private and could change at anytime DO NOT RELY ON THIS BEHAVIOR. Shahdee 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted July 29, 2015 Share Posted July 29, 2015 The two APIs are not related, using the loader to warm the internal texture cache for use with those methods is a hack and should not be used in production code.I didn't know that! I naively assumed the `from` methods were just dumb, higher lever wrappers that accessed the texture cache with the convenience of less code to type. Is there a way of using the loader values without having to create a string identifier for the textures?For example, instead of this:.add('image1', 'image1.png')Could I use this:.add('image1.png')And, if I can, how would I access it in the loader?var sprite1 = new PIXI.Sprite(PIXI.loader.????????); Quote Link to comment Share on other sites More sharing options...
bubamara Posted July 29, 2015 Share Posted July 29, 2015 var sprite1 = new PIXI.Sprite(PIXI.loader.resources['image1.png'].texture);edit: forgot to add .texture at the end d13 and Shahdee 2 Quote Link to comment Share on other sites More sharing options...
xerver Posted July 29, 2015 Share Posted July 29, 2015 Exactly what bubamara said. The resource loader keys by the key you pass in, if you don't pass one in it uses the url as the key. d13 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted July 29, 2015 Share Posted July 29, 2015 Thanks guys, that's just what I was looking for! Quote Link to comment Share on other sites More sharing options...
d13 Posted July 29, 2015 Share Posted July 29, 2015 Another question:What's the best way to access frame ids from a loaded texture atlas on the `resources` object? Quote Link to comment Share on other sites More sharing options...
xerver Posted July 30, 2015 Share Posted July 30, 2015 Another question:What's the best way to access frame ids from a loaded texture atlas on the `resources` object? Exactly how they are written out in the json. That is usually filename if using JSON Hash format, or numeric index if using JSON Array format. It will look like this:PIXI.loader.add("sheet", "mysheet.json").load(function (loader, resources) { resources.sheet.textures['some_frame.png'];}); Quote Link to comment Share on other sites More sharing options...
d13 Posted July 30, 2015 Share Posted July 30, 2015 Thanks so much, Xerver,! So they're all in the JSON resource's `textures` object - I'll look for them there. I have two more questions related to this topic. 1. If I'm using pre-loading textures with the loader, is it still acceptable to create a sprite's by referencing the texture cache, like this?var sprite = new PIXI.Sprite(PIXI.utils.TextureCache["anyTexture.png"]);2. Should I access video textures in the same way, like this?var sprite = new PIXI.Sprite(PIXI.loader.resources['video.mp4'].texture);... and is there an alternative to using `fromVideoUrl` - or is that `from` method OK because it doesn't reference a loaded texture? Quote Link to comment Share on other sites More sharing options...
xerver Posted July 30, 2015 Share Posted July 30, 2015 1. I would just avoid the TextureCache, you don't need to use it and it won't support all the features in the loader. Just treat the resources object like the texture cache, its easier to use anyway. 2. The loader does not currently have support for loading videos and parsing them into video textures. To be clear all the `.from*()` methods are OK, nothing wrong with using them. Just don't try to mix them with the loader and be clever about preloading usages of those APIs. Assume if you do `.from*()` it will make a request for the url you pass in. d13 1 Quote Link to comment Share on other sites More sharing options...
d13 Posted August 4, 2015 Share Posted August 4, 2015 2. The loader does not currently have support for loading videos and parsing them into video textures. Are from `fromVideo` and fromVideoUrl` currently the only way to load video textures? Quote Link to comment Share on other sites More sharing options...
xerver Posted August 4, 2015 Share Posted August 4, 2015 Are from `fromVideo` and fromVideoUrl` currently the only way to load video textures? Technically no, but there is no parser on the loader yet that automatically will create a texture for you yet. But the resource loader supports loading videos. Quote Link to comment Share on other sites More sharing options...
lookitscook Posted January 21, 2016 Share Posted January 21, 2016 I'm trying to load a video into a RenderTexture and then read the pixels back out later. I noticed the note regarding textures in RenderTexture needing to be preloaded, so I assume the video needs to be preloaded to get non-zero values from getPixel. Is it possible to preload videos and use them as textures? Quote Link to comment Share on other sites More sharing options...
Exca Posted January 22, 2016 Share Posted January 22, 2016 On 30.7.2015 at 3:47 AM, xerver said: Exactly how they are written out in the json. That is usually filename if using JSON Hash format, or numeric index if using JSON Array format. It will look like this: PIXI.loader.add("sheet", "mysheet.json").load(function (loader, resources) { resources.sheet.textures['some_frame.png'];}); Is there a way to get the image without knowing what sheet it was in without using texturecache? I have a situation where I optimize the size of sheets by building them based on color and then storing them as 8bit images whenever color amount is small enough, which means that the images swap sheets pretty often. I could build my own cache by going through the assets in sheets and mapping them, but seeing as the textureCache already contains that information that would seem a bit of a waste to do it twice. Is textureCache the correct way to get images in this situation? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 22, 2016 Share Posted January 22, 2016 1) For now you can use Sprite.fromImage and Texture.fromImage if you dont know which sheet has it. thats correct way for pixiv3. Those two methods work through global texture cache. 2) @xerver way is different but not features were implemented for it: add special middleware to loader that will create cache for that specific loader. @xerver thinks that global cache is evil. I admit, it is true for big applications with lots of dynamic textures Exca 1 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.