jSwtch Posted August 1, 2018 Share Posted August 1, 2018 Hello, I have seen different methods for creating a sprite from a texture. Is there a difference? I am mainly looking at PIXI.Texture.fromImage(... vs renderer.generateTexture(... sprite = new PIXI.Sprite( new PIXI.Texture.fromImage( "...img/path" ) ); app.stage.addChild(sprite); let texture: PIXI.Texture = renderer.generateTexture("...img/path"); let sprite: PIXI.Sprite = new PIXI.Sprite(texture); stage.addChild(sprite); Also for particle emitters is it better to use sprites or textures? I see that (https://github.com/pixijs/pixi.js/wiki/v4-Performance-Tips? "textures are automatically managed by a Texture Garbage Collector". However most examples of particle emitters I see seem to use sprites. Edit: I see that sprites are textures Quote Link to comment Share on other sites More sharing options...
xerver Posted August 1, 2018 Share Posted August 1, 2018 Quote I am mainly looking at PIXI.Texture.fromImage(... vs renderer.generateTexture(... generateTexture doesn't take a string. It takes a DisplayObject and creates a texture from rendering the object. Also, PIXI.Texture.fromImage is a function not a constructor. Don't call it with new. You should either do `new PIXI.Texture()` or `PIXI.Texture.fromImage()`, don't combine them. Quote Also for particle emitters is it better to use sprites or textures? Textures don't render, sprites do. Textures are just images, sprites combine images (textures) with a transform to make it renderable. Quote However most examples of particle emitters I see seem to use sprites. I bet all of them do, because you can't render a texture because it isn't a DisplayObject. Quote Edit: I see that sprites are textures They are not. Sprites are DisplayObjects, and they contain a reference to a Texture. Textures are a standalone object that cannot be rendered. jSwtch 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.