ShotgunJed

Can a html <img> use a Pixi Texture object?

Recommended Posts

I know that a texture can be loaded from the website's assets (e.g: "/foo.png"). Is it possible to do something like this:

let texture = (some texture from Pixi)

document.body.appendChild(<img width=420 height=420 src=texture>);

Can a html element use a pixi texture?

Share this post


Link to post
Share on other sites

You'd want to render the texture to another canvas and append that to the body. Or if you really have to use an image you could render the texture to an off screen canvas, then use canvas toDataUrl to get it into an image element

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

You assign the output of canvas toDataUrl as the image src

Share this post


Link to post
Share on other sites

I've been a slightly different variant: using a PIXI.Sprite (which has additional content) as an image source

var imgSRC = renderer.extract.canvas(mySprite).toDataURL('image/png'); 

var img = document.createElement('IMG');

img.src = imgSRC;
img.style.width = '100%';
img.style.height = 'auto';
	
document.body.appendChild(img);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.