Render text into different frames of a texture

How can i manually create a texture, add text to a frame and different text to another frame?

I saw examples with images and sprites, but not with text.

Possibly a simple thing, but i really didn’t see the solution.

Could somebody confirm, if this is the right way todo it?
Or could it be done easier?

const rt = this.scene.add.renderTexture(0, 0, 100, 300)
  .setIsSpriteTexture(true) // without everything is flipped
  .setVisible(false)

const text1 = this.scene.add.text(0, 0, 'Text 1')
  .setVisible(false)
rt.draw(text1, 0, 0)

const text2 = this.scene.add.text(0, 0, 'Text 2')
  .setVisible(false)
rt.draw(text2, 0, 100)

rt.texture.add('area1', 0, 0, 0, 100, 100)
rt.texture.add('area2', 0, 0, 100, 100, 100)
1 Like

That’s right. But I think you can reuse one text object (style, set text, draw, repeat). That will save creating extra canvases.

1 Like