Jump to content

Creating sprite from texture


jSwtch
 Share

Recommended Posts

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

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...