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

**URL:** <https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589>\
**Category:** Phaser 3\
**Created:** [May 14, 2021, 8:13am UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589 "2021-05-14T08:13:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prolight](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/prolight/32/5174_2.png) [@Prolight](https://phaser.discourse.group/u/Prolight)\
**Post date:** [May 14, 2021, 8:13am UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/1 "2021-05-14T08:13:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [May 14, 2021, 8:40am UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/2 "2021-05-14T08:40:08Z")

</div>

> **[Phaser - Examples - Trail2](https://phaser.io/examples/v3/view/game-objects/render-texture/trail2)**
>
> Desktop and Mobile HTML5 game framework. A fast, free and fun open source framework for Canvas and WebGL powered browser games.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 14, 2021, 4:22pm UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/3 "2021-05-14T16:22:32Z")

</div>

> **[Phaser - Examples - Batch Draw Sprite](https://phaser.io/examples/v3/view/game-objects/render-texture/batch-draw-sprite)**
>
> Desktop and Mobile HTML5 game framework. A fast, free and fun open source framework for Canvas and WebGL powered browser games.

---

<div class="post-metadata">

**Author:** ![Prolight](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/prolight/32/5174_2.png) [@Prolight](https://phaser.discourse.group/u/Prolight)\
**Post date:** [May 14, 2021, 9:25pm UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/4 "2021-05-14T21:25:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Antriel](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/antriel/32/15_2.png) [@Antriel](https://phaser.discourse.group/u/Antriel)\
**Post date:** [May 15, 2021, 7:39am UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/5 "2021-05-15T07:39:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 15, 2021, 3:14pm UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/6 "2021-05-15T15:14:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 18, 2021, 2:30pm UTC](https://phaser.discourse.group/t/how-to-render-an-image-asset-on-fly-without-creating-a-game-object/9589/7 "2021-05-18T14:30:28Z")

</div>

> [@Cull blitter bobs by camera view (Phaser 3)](https://phaser.discourse.group/t/cull-blitter-bobs-by-camera-view-phaser-3/9601):
>

> [@Giant render texture scrolling starfield (Phaser 3)](https://phaser.discourse.group/t/giant-render-texture-scrolling-starfield-phaser-3/9613):
>
> 10000 stars within 8000 × 6000px, visible portion drawn onto a 800 × 600px render texture. Scroll with cursor keys.

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.
