Jump to content

Trouble Using RenderTexture


Recommended Posts



I am trying to combine images dynamically using the RenderTexture class, but I'm having trouble getting anything to display.


Here is the code:

var uiElement = new Phaser.Sprite(game, 0, 0, 'uiElement', 0);
var menu = game.add.renderTexture('menu',1000, 1000);
menu.render(uiElement, 200, 200);
'uiElement' is loaded at the beginning of the game.
Thanks for the help!
Link to comment
Share on other sites

  • 3 months later...


I struggle with that too. Basically the right way of doing this looks something like this,


var img = game.make.image(0, 0, 'texture', 'frame');

var tex = game.add.renderTexture(img.width, img.height, 'name', true);

tex.renderXY(img, 0, 0, true);

var sprite = game.add.sprite(0, 0, tex);


You're welcome!

Link to comment
Share on other sites

  • 1 year later...

worth noting as of 2.4.0 that the 2nd argument of render is a matrix

render(displayObject, matrix, clear)This function will draw the display object to the RenderTexture.In versions of Phaser prior to 2.4.0 the second parameter was a Phaser.Point object. This is now a Matrix allowing you much more control over how the Display Object is rendered. If you need to replicate the earlier behavior please use Phaser.RenderTexture.renderXY instead.If you wish for the displayObject to be rendered taking its current scale, rotation and translation into account then either pass null, leave it undefined or pass displayObject.worldTransform as the matrix value.

you should be able to do this then:

var uiElement = new Phaser.Sprite(game, 0, 0, 'uiElement', 0);var menu = game.add.renderTexture('menu',1000, 1000);var m = new Phaser.Matrix()m.translate(200,200)menu.render(uiElement, m, false);

but yes you could also use renderXY here

Link to comment
Share on other sites


  • Recently Browsing   0 members

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