How to render an image/asset on fly without creating a game object

Good afternoon!

I was wondering if there was/is anyway I can render a texture on fly without adding an image object to the scene. I don’t want to create image objects because I want to load a ton of images into the scene but not process all of them at once or have them all in memory since it’s just a static image.

If you’re curious as to why I want to do this: I’m making a space exploration game and I have a spatial partitioning system so everything doesn’t get processed at once. But even just loading image objects into the scene is too much. I have to conserve memory.

I’m coming from Processing JS (PJS).

In PJS there’s a method called image
So I want to do something like this:
this.scene.image(imgObj, x, y);

Also I’ve already figured how to place the images but I’m not going to explain it since it’s complex. But I’ll tell you this: I’m using Phaser.Math.RandomDataGenerator as seeded randomness.

So does anyone know of a way to do this? I know there’s blitters and renderTextures but I don’t know how to use them and if they apply here or can accomplish this.

Okay but how do I take in account for camera scale and rotation if the renderTexture fills the screen?

I can see two approaches:

  1. Do create the sprites and other game objects, as needed, and kill/respawn them as you move through the world. That is, handle the issue – having too many game objects – manually.
  2. Do what you want to do, that is render only the relevant sprites every frame. Phaser doesn’t really expose a way for doing that, but you can still do it. Look at the source for an Image, its renderer, and you will find how it calls batchQuad, at some point.
    Calling that yourself will work the way you want, but you will lose all the things Phaser’s game objects give you, of course. E.g. it’s up to you to calculate the proper texture uvs, sprite scale/position, etc. You can mostly copy Phaser’s code, and adapt it for your needs, making a sort of one-frame, no-allocation sprite draw function.

RenderTexture has an internal camera. I think you could move it like the main camera.

The render texture internal camera doesn’t work as well as I thought, as it doesn’t scroll the same way a display camera does.