Jump to content

Drawing a Sprite to a canvas


dst
 Share

Recommended Posts

I know that I can draw a Sprite to a RenderTexture but is there any way to draw a sprite to a canvas element? Or somehow get a canvas or image element out of a RenderTexture?

 

I would like to draw a complex sprite with multiple children to a canvas/image so that I can then perform globalCompositeOperations on it i.e. draw a source image into it using "source-atop". For example:

var sourceImage = new Image();sourceImage.src = "mySourceImage.png";var mySpriteCanvas = mySprite.toCanvas();mySpriteCanvas.context.globalCompositeOperation = 'source-atop';mySpriteCanvas.context.drawImage(sourceImage, 0, 0);var baseTexture = new PIXI.BaseTexture(mySpriteCanvas);var texture = new PIXI.Texture(baseTexture);var myCompositeSprite = new PIXI.Sprite(texture);stage.addChild(myCompositeSprite);

Is it possible to do something like this?

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...