Jump to content

Phaser texture-from-canvas update issues


Recommended Posts


I'm trying to create a Phaser.Sprite using a canvas-based texture (another attempt to connect ThreeJS with Phaser, if you're interested), but I have some issues.

My first attempt before doing all of this was forcing ThreeJS render into a Phaser.BitmapData, but maybe you already thinking it was a non-optimal solution (with small canvases works fine, but if you increase the resolution, the perfomance will slow down, aaaaand you're limited to take frames from only 2d-non-webgl context).

Faster solutions? Yes, maybe Phaser.RenderTexture was a good idea, but I never find a way how to render a canvas into it. (Since canvas is not a PIXI.DisplayObject).

So, after researching a while, I came with the idea of render the canvas more directly to the sprite, doing this ...

sprite = new Phaser.Sprite(game, x, y, null);

//There's a canvas named "renderHere" where stuff is rendered.
sprite.setTexture(PIXI.Texture.fromCanvas(document.getElementById("renderHere"), PIXI.scaleModes.DEFAULT));

... it works BUT it justs render the fist frame. Yes, I need to update it. I found that in some Github issues, people mentioned that I need to refresh the textures in PIXI doing this:


But Surprise!: PIXI.texturesToUpdate is undefined!!! :D. (I'm using Phaser v2.4.6 with Pixi.js v2.2.9 if that's a clue). I'm thinking it is a issue about PIXI versions and such things, but I don't know really.

So... Any ideas where texturesToUpdate was? O there's another workaround to refresh the texture? Or there's a direct way to render canvases in RenderTextures? Or maybe I need to quit programming and be a night exotic dancer? 

Thanks in advance :) 

Link to comment
Share on other sites


  • Recently Browsing   0 members

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