Display Tiles Grid

In rpg_core I found this but I won't get them working, at best I have "clearRect is not defined" or "cannot read property '' of null"
JavaScript:
Bitmap.prototype.clearRect = function(x, y, width, height) {
    this._context.clearRect(x, y, width, height);
    this._setDirty();
};
JavaScript:
Bitmap.prototype.clear = function() {
    this.clearRect(0, 0, this.width, this.height);
};
JavaScript:
Bitmap.prototype.clear = function() {
    get: function() {
        return new Rectangle(0, 0, this.width, this.height);
    this.clearRect(0, 0, this.width, this.height);
   }
};
In rpg_core I found this but I won't get them working, at best I have "clearRect is not defined" or "cannot read property '' of null"
JavaScript:
Bitmap.prototype.clearRect = function(x, y, width, height) {
    this._context.clearRect(x, y, width, height);
    this._setDirty();
};
JavaScript:
Bitmap.prototype.clear = function() {
    this.clearRect(0, 0, this.width, this.height);
};
JavaScript:
Bitmap.prototype.clear = function() {
    get: function() {
        return new Rectangle(0, 0, this.width, this.height);
    this.clearRect(0, 0, this.width, this.height);
   }
};
The bitmap is different from pixi graphics so you won't be able to use any of the code. If you want to use the bitmap functions, the only solution I can think of is to create a canvas, get the image data, and then create a new bitmap from that data.
The bitmap is different from pixi graphics so you won't be able to use any of the code. If you want to use the bitmap functions, the only solution I can think of is to create a canvas, get the image data, and then create a new bitmap from that data.
In this case, how you draw lines in the same way that PIXI.Graphics in using Bitmap?
In this case, how you draw lines in the same way that PIXI.Graphics in using Bitmap?
To be honest, I am not entirely sure beyond that. Canvas has similar functions that you posted for Bitmap you can use and that's about as far as I can get for now.

Also, if you are dynamically drawing things on to the canvas, you wouldn't want it to be a bitmap anyways since you are editing the actual graphic in real time. (Bitmap is more for a static image).

I've attempted several approaches to try to convert the graphics data to a bitmap but it has not worked. It is much easier to just use the ImageManager with a pre-drawn image.

Maybe when I get better in this area I'll be able to help you better, but this is all I can do for now.

W3Schools - Canvas API
To be honest, I am not entirely sure beyond that. Canvas has similar functions that you posted for Bitmap you can use and that's about as far as I can get for now.

Also, if you are dynamically drawing things on to the canvas, you wouldn't want it to be a bitmap anyways since you are editing the actual graphic in real time. (Bitmap is more for a static image).

I've attempted several approaches to try to convert the graphics data to a bitmap but it has not worked. It is much easier to just use the ImageManager with a pre-drawn image.

Maybe when I get better in this area I'll be able to help you better, but this is all I can do for now.

W3Schools - Canvas API
Ok I was able to test on w3schools/mozilla and for both its work perfectly, I tested with that:
JavaScript:
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");

ctx.lineWidth = 10;
ctx.strokeStyle = "red";
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);
But I don't no why but it's didn't work on rpg maker mv, I have added on the index.html file
HTML:
<canvas id="myCanvas" width="816" height="816"></canvas>

I don't know what I messed.

EDIT:
by adding this to the script I have my drawing but I have a error message: ReferenceError bitmap is not defined
Code:
bitmap._baseTexture.update();
Ok I was able to test on w3schools/mozilla and for both its work perfectly, I tested with that:
JavaScript:
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");

ctx.lineWidth = 10;
ctx.strokeStyle = "red";
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);
But I don't no why but it's didn't work on rpg maker mv, I have added on the index.html file
HTML:
<canvas id="myCanvas" width="816" height="816"></canvas>

I don't know what I messed.

by adding
Code:
bitmap._baseTexture.update();
I have my drawing but I have a error message: ReferenceError bitmap is not defined
It is much simpler to convert it to a sprite to add to the scene than to try to go the bitmap route.

Try:
JavaScript:
const c = document.createElement('myCanvas');
const ctx = c.getContext('2d');
c.setAttribute('width', 300);
c.setAttribute('height', 200);

ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);

const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(spr);
It is much simpler to convert it to a sprite to add to the scene than to try to go the bitmap route.

Try:
JavaScript:
const c = document.createElement('myCanvas');
const ctx = c.getContext('2d');
c.setAttribute('width', 300);
c.setAttribute('height', 200);

ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);

const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(c);
Nope If I add the script below I have "TypeError Cannot set property '_parentID' of undefined"
Code:
const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(c);
And it's normal because with ctx I don't have parent/child anymore, but honestly I just need to know with what I must define bitmap and I think its will be work
Nope If I add the script below I have "TypeError Cannot set property '_parentID' of undefined"
Code:
const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(c);
And it's normal because with ctx I don't have parent/child anymore, but honestly I just need to know with what I must define bitmap and I think its will be work
Edit: my fault - it's spr at the end, not c and I had to use 'canvas' instead of 'myCanvas' - for you, the naming might need to be 'myCanvas':
JavaScript:
SceneManager._scene._spriteset.addChild(spr)

canvas.png


JavaScript:
const c = document.createElement('canvas');
const ctx = c.getContext('2d');
c.setAttribute('width', 300);
c.setAttribute('height', 200);

ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);

const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(spr);

You also did the first part of the code I rewrote, right? Just double checking if I missed something. I'm no longer at the computer but I'll have to check it out tomorrow then. Thanks for your patience on this.
Edit: my fault - it's spr at the end, not c and I had to use 'canvas' instead of 'myCanvas' - for you, the naming might need to be 'myCanvas':
JavaScript:
SceneManager._scene._spriteset.addChild(spr)

View attachment 333839

JavaScript:
const c = document.createElement('canvas');
const ctx = c.getContext('2d');
c.setAttribute('width', 300);
c.setAttribute('height', 200);

ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);

const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(spr);

You also did the first part of the code I rewrote, right? Just double checking if I missed something. I'm no longer at the computer but I'll have to check it out tomorrow then. Thanks for your patience on this.
Oh f*ck yes dude it's work! One last thing: "ctx.lineWidth" determine the wid stroke and "ctx.strokeStyle" the color; I would like apply different styles without do it manually, at first I wanted to use css but it's impossible to do it on javascript element, so I'm wonder if it's possible to achieve the same result with array?
Oh f*ck yes dude it's work! One last thing: "ctx.lineWidth" determine the wid stroke and "ctx.strokeStyle" the color; I would like apply different styles without do it manually, at first I wanted to use css but it's impossible to do it on javascript element, so I'm wonder if it's possible to achieve the same result with array?
Glad it works!

The only thing I can think of is to put your parameters into a function or object and pull the info from there with a loop or something. All depends on your workflow.
Glad it works!

The only thing I can think of is to put your parameters into a function or object and pull the info from there with a loop or something. All depends on your workflow.
1 good new and 1 bad news:

In using variable to change stroke colors work perfectly.
JavaScript:
$gameVariables.setValue(id, ['num0', 'num1', 'num2', 'num3', 'num4', etc...]);
JavaScript:
 ctx.strokeStyle = $gameVariables.value(id)[num];

Problem, I cannot display more that one drawing at time
Ok I think I found a start of resolving encouraging:
-With PIXI.graphics I can draw many drawings with the same script but I can delete them in any order.
-With Canvas I can delete them like I want but I cannot draw more that 1 times.

But apparently, it exist a way to convert PIXI into Bitmap:
JavaScript:
const container = new PIXI.Container();
container.addChild();

function getBitmapContainer(container, width, height) {
  const bitmap = new Bitmap(width, height);
  const context = bitmap._context;
  const renderTexture = PIXI.RenderTexture.create(width, height);
  Graphics._renderer.render(container, renderTexture);
  const canvas = Graphics._renderer.extract.canvas(renderTexture);
  context.drawImage(canvas, 0, 0);
  renderTexture.destroy({ destroyBase: true });
  bitmap._setDirty();
  return bitmap;
}

const snap = getBitmapContainer(container, 400, 500);
const sprite = new Sprite(snap);
this.addChild(sprite);

I have an error "Cannot read property 'parent' of undefined", the error look like PIXI isn't defined:
do someone know with what I must define PIXI?
Ok I think I found a start of resolving encouraging:
-With PIXI.graphics I can draw many drawings with the same script but I cannot delete them in any order.
-With Canvas I can delete them like I want but I cannot draw more that 1 times.

But apparently, it exist a way to convert PIXI into Bitmap:
JavaScript:
const container = new PIXI.Container();
container.addChild();

function getBitmapContainer(container, width, height) {
  const bitmap = new Bitmap(width, height);
  const context = bitmap._context;
  const renderTexture = PIXI.RenderTexture.create(width, height);
  Graphics._renderer.render(container, renderTexture);
  const canvas = Graphics._renderer.extract.canvas(renderTexture);
  context.drawImage(canvas, 0, 0);
  renderTexture.destroy({ destroyBase: true });
  bitmap._setDirty();
  return bitmap;
}

const snap = getBitmapContainer(container, 400, 500);
const sprite = new Sprite(snap);
this.addChild(sprite);

I have an error "Cannot read property 'parent' of undefined", the error look like PIXI isn't defined:
do someone know with what I must define PIXI?
Hoping your hard work can finally pay off - here is what I did to get it all on there with bridging your original code:
JavaScript:
const s = SceneManager._scene._spriteset;
const w = 400, h = 500;
const container = new PIXI.Container();
s.addChild(container);

const bitmap = new Bitmap(w, h);
const ctx = bitmap._context;
const r = PIXI.RenderTexture.create(w, h);
Graphics._renderer.render(container, r);
ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);
r.destroy({destroyBase: true});
bitmap._setDirty();

const spr = new Sprite(bitmap);
container.addChild(spr);
Edit: removed some code above that was unnecessary

s1.png

I can reference the bitmap and clear from there or continue to draw with bitmap._context and follow the context stuff (strokeStyle, beginPath, lineTo, closePath, etc.). In the example above, I referenced the bitmap and cleared from 0,0 to 200, 200 and it worked after the bitmap was loaded (bitmap.clearRect(0, 0, 200, 200).

Hope this helps - I have also been working a lot on bitmap so I hope this has helped you and others. I am sure there are easier ways, of course. In the end, this is a great learning experience.

Thanks!

Edit: for your specific post, you are missing a few things. Also, it doesn't seem like there is anything for canvas so when you use drawImage, you might not get anything since you created a blank, new bitmap (I could be wrong though since I haven't tested your code).

Try:
JavaScript:
const s = SceneManager._scene._spriteset;
const container = new PIXI.Container();
s.addChild(container);

function getBitmapContainer(container, width, height) {
  const bitmap = new Bitmap(width, height);
  const context = bitmap._context;
  const renderTexture = PIXI.RenderTexture.create(width, height);
  Graphics._renderer.render(container, renderTexture);
  const canvas = Graphics._renderer.extract.canvas(renderTexture);
  context.drawImage(canvas, 0, 0);
  renderTexture.destroy({ destroyBase: true });
  bitmap._setDirty();
  return bitmap;
}

const snap = getBitmapContainer(container, 400, 500);
const sprite = new Sprite(snap);
s.addChild(sprite);
Hoping your hard work can finally pay off - here is what I did to get it all on there with bridging your original code:
JavaScript:
const s = SceneManager._scene._spriteset;
const w = 400, h = 500;
const container = new PIXI.Container();
s.addChild(container);

const bitmap = new Bitmap(w, h);
const ctx = bitmap._context;
const r = PIXI.RenderTexture.create(w, h);
Graphics._renderer.render(container, r);
ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
ctx.clearRect(70, 150, 50, 50);
r.destroy({destroyBase: true});
bitmap._setDirty();

const spr = new Sprite(bitmap);
container.addChild(spr);
Edit: removed some code above that was unnecessary

View attachment 334917
I can reference the bitmap and clear from there or continue to draw with bitmap._context and follow the context stuff (strokeStyle, beginPath, lineTo, closePath, etc.). In the example above, I referenced the bitmap and cleared from 0,0 to 200, 200 and it worked after the bitmap was loaded (bitmap.clearRect(0, 0, 200, 200).

Hope this helps - I have also been working a lot on bitmap so I hope this has helped you and others. I am sure there are easier ways, of course. In the end, this is a great learning experience.

Thanks!

Edit: for your specific post, you are missing a few things. Also, it doesn't seem like there is anything for canvas so when you use drawImage, you might not get anything since you created a blank, new bitmap (I could be wrong though since I haven't tested your code).

Try:
JavaScript:
const s = SceneManager._scene._spriteset;
const container = new PIXI.Container();
s.addChild(container);

function getBitmapContainer(container, width, height) {
  const bitmap = new Bitmap(width, height);
  const context = bitmap._context;
  const renderTexture = PIXI.RenderTexture.create(width, height);
  Graphics._renderer.render(container, renderTexture);
  const canvas = Graphics._renderer.extract.canvas(renderTexture);
  context.drawImage(canvas, 0, 0);
  renderTexture.destroy({ destroyBase: true });
  bitmap._setDirty();
  return bitmap;
}

const snap = getBitmapContainer(container, 400, 500);
const sprite = new Sprite(snap);
s.addChild(sprite);
I try your code and it's work pretty well (compared to the script I found and you try to fixed), but I cannot manage to us properly bitmap.clearRect():
When I use it in the same script its work but when I try to used it in a external event I just an error "ReferenceError bitmap is not defined".
Even when I try to define bitmap in the same way that your script nothing happen.
I try your code and it's work pretty well (compared to the script I found and you try to fixed), but I cannot manage to us properly bitmap.clearRect():
When I use it in the same script its work but when I try to used it in a external event I just an error "ReferenceError bitmap is not defined".
Even when I try to define bitmap in the same way that your script nothing happen.
To use it externally after defining it, you will need to reference the bitmap.

Add this to the list right before you add the child (use spr or sprite, whatever you referenced ans also include the container):
JavaScript:
spr.name = 'house';
container.name = 'container';

Then, to use clearRect, do:
JavaScript:
const s = SceneManager._scene._spriteset.getChildByName('container');
const spr = s.getChildByName('house');
spr.bitmap.clearRect(0, 0, 300, 300);
The goal is to find the child under the property/object of where you added it. If you added it in spriteset, you need to find the child under that object first. Since there is a container, you also have to find that part.

Thing to consider: keep in mind that if you run this script call multiple times, the game will create multiple children with the same name so you will have to delete them all separately.

Finding the child by their name will only return the first name that matches. Check the console for all children added to the scene.
It doesn't work, I can only clean the first child.

The goal is to find the child under the property/object of where you added it. If you added it in spriteset, you need to find the child under that object first. Since there is a container, you also have to find that part.
JavaScript:
const s = SceneManager._scene._spriteset; 
const w = 500, h = 500; 
const container = new PIXI.Container(); 
container.name = 'container'; 
s.addChild(container); 

const bitmap = new Bitmap(w, h); 
const ctx = bitmap._context; 
const r = PIXI.RenderTexture.create(w, h); 
Graphics._renderer.render(container, r); 
ctx.lineWidth = 10; 
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
r.destroy({destroyBase: true}); 
bitmap._setDirty(); 

const spr = new Sprite(bitmap); 
spr.name = 'house'; 
container.addChild(spr);
If I'm not wrong with this script, parent-child are: s -> container -> house, but its can only clear with spr.

Thing to consider: keep in mind that if you run this script call multiple times, the game will create multiple children with the same name so you will have to delete them all separately.
After, maybe the problem is you define child with ".name", I'm look if there is a way to define a child with a position xy.
If clearRect can only works for the first child with the same name then, if each child are defined by a specific coordinate I guess it will work in the same way:
in my case each drawings cannot be have the same coordinate so I don't see why it wouldn't work


I'm looking to see if its possible to do it with PIXI.Point, "getGlobalPosition", "toGlobal". After maybe there are a more radical solution in using "removeChild"/"removeChildren" before to clean them.
It doesn't work, I can only clean the first child.


JavaScript:
const s = SceneManager._scene._spriteset;
const w = 500, h = 500;
const container = new PIXI.Container();
container.name = 'container';
s.addChild(container);

const bitmap = new Bitmap(w, h);
const ctx = bitmap._context;
const r = PIXI.RenderTexture.create(w, h);
Graphics._renderer.render(container, r);
ctx.lineWidth = 10;
ctx.strokeStyle = 'red';
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
r.destroy({destroyBase: true});
bitmap._setDirty();

const spr = new Sprite(bitmap);
spr.name = 'house';
container.addChild(spr);
If I'm not wrong with this script, parent-child are: s -> container -> house, but its can only clear with spr.


After, maybe the problem is you define child with ".name", I'm look if there is a way to define a child with a position xy.
If clearRect can only works for the first child with the same name then, if each child are defined by a specific coordinate I guess it will work in the same way:
in my case each drawings cannot be have the same coordinate so I don't see why it wouldn't work


I'm looking to see if its possible to do it with PIXI.Point, "getGlobalPosition", "toGlobal". After maybe there are a more radical solution in using "removeChild"/"removeChildren" before to clean them.
The issue is that you are adding more "children" when you draw a new drawing. There is no issue with the naming because it is more like how there are people with the same name.

Let's say child 3 is named house and then child 4 is named house as well. Every child can be named house because they exist in a different part of the array. Like this:

['Jim', 'Tom', 'House', 'House']

Each one is in a different part of the array even with the same name. Or,like this:

[0,0,0,0,0]
Or
['house', 'house', 'house', 'house']

When you reference a new bitmap, you create a new area that also needs to be cleared. You cannot ask the computer to clear one bitmap and expect it to clear all of it without telling it that (A loop is needed).

So, you run a loop instead. Let's say all the children you added has the name 'house' and there are 7 of them. Also, you added them all to 1 container only. You need to do:
JavaScript:
const s = SceneManager._scene._spriteset.getChildByName('container');
for (const child of s.children) {
  child.bitmap.clearRect(0, 0, 200, 200);
}
This means that you are clearing that area from 0,0 to 200,200 for every child you added in the container. If you only want to clear the children named 'house' and there were other children with different names, you filter it out:
JavaScript:
const s = SceneManager._scene._spriteset.getChildByName('container');
for (const child of s.children) {
  if (child.name === 'house') child.bitmap.clearRect(0, 0, 200, 200);
}
You seem like you can work through this pretty well so I am going to leave the rest up to you.

The flexibility of the bitmap/sprite/canvas drawing is awesome, but it also means that you need to keep track of everything.

If you draw it on the same bitmap without creating a new one, then one clearRect would work. That means you need to get the ._context of that bitmap and then starting drawing on that specific one without creating a new bitmap.

It sounds to me like every drawing you are creating is assigned a new bitmap. Therefore, you need to specifically reference every bitmap you created in order to clear it properly.

Same names with different positions in the array is fine - like I said, it's just another way to get the child. Use the index, use the array, use anything that works with you. When it doesn't work, take a step back and try it a different approach.

Thanks!
You seem like you can work through this pretty well so I am going to leave the rest up to you.
I think you overestimate me, I have too few knowledge about javascript and at best I can just understand the script structure but I'm still unable to do it by myself.

I don't understand how your loop work because in both case its work only the first child.

EDIT:

OK I get it, in my script I have this:
JavaScript:
const bitmap = new Bitmap(w, h);

So basically each time I create a new draw I create a new bitmap, so the solution will be to redirect all drawings on the first bitmap or to clear all bitmap.
Also it's just a detail but if it must clean them one by one (with the possibilty to loop them), there is way to clean the last child first?
I don't understand how your loop work because in both case its work only the first child.
I am going to take a guess in that you are also creating a new container each time to that scene. So you will need to loop through all containers as well (assuming you named them 'container'):
JavaScript:
const s = SceneManager._scene._spriteset.children;
for (let i = 0; i < s.length; i++) {
  if (s[i].name === 'container') {
    for (let j = 0; i < s.children.length; j++) {
      const c = s[i].children[j];
      if (c.name === 'house') c.clearRect(0, 0, 200, 200);
    }
  }
}
If you must clean the last one you put on there first, then you need to find the last child and destroy or clear it one by one since the loop will happen instantly:
JavaScript:
const s = SceneManager._scene._spriteset.children;
const child = s[s.length - 1].children;
child[child.length].destroy();
or
JavaScript:
const s = SceneManager._scene._spriteset.children;
const child = s[s.length - 1].children;
child[child.length - 1].bitmap.clearRect(0,0,200,200);
With this code, you need to do length - 2, and then length - 3...until you cycle through everything. Doing it with a loop will just do it all at once, even in reverse. It will be too quick for the player to see it happening in reverse (unless you set up some wait times inside an event, and that is a whole other conversation).

It becomes harder to deal with because you can't always keep track of what you added and you add more guesswork to your workload. Destroy() might be better if you know you aren't going to use that bitmap anymore.

To be able to draw on the same bitmap, as I stated earlier, you have to find that bitmap and then reference the context.

Let's say you use the script above which created a new container and a new bitmap with the house. You then cleared it (not destroy) and you want to draw something else on it - you need to find that specific container and bitmap before you can draw on it .

In this example, I know that the last child I added is the container and the last child I added to the container is the house so I just need to do .length - 1 for each of them:
JavaScript:
const s = SceneManager._scene._spriteset.children;
const child = s[s.length - 1].children;
const bitmap = child[child.length - 1].bitmap;
const ctx = bitmap._context;
ctx.strokeStyle = 'red';
ctx.fillStyle = 'blue';
ctx.strokeRect(0, 0, 200, 200);
ctx.fillRect(100, 200, 200, 300);
bitmap._setDirty();
Doing it like this allows me to reference that specific bitmap to add more things to it. Again, this is ASSUMING that it was the last thing you added to the scene. Otherwise, you have to search for it (use the console to look at the array of children and go from there).

Hope this helps! Anything else will have to come from experimenting because I don't know your true goals and what you are after and everything that you do. You need to adapt to it - the code above won't work if you add new children to the scene (which is why I name everything).

And even then, if you add more, you need to be ready to work with more and also be ready to find out where everything is located.

Happy hunting!
I am going to take a guess in that you are also creating a new container each time to that scene. So you will need to loop through all containers as well (assuming you named them 'container'):
JavaScript:
const s = SceneManager._scene._spriteset.children;
for (let i = 0; i < s.length; i++) {
  if (s[i].name === 'container') {
    for (let j = 0; i < s.children.length; j++) {
      const c = s[i].children[j];
      if (c.name === 'house') c.clearRect(0, 0, 200, 200);
    }
  }
}
If you must clean the last one you put on there first, then you need to find the last child and destroy or clear it one by one since the loop will happen instantly:
JavaScript:
const s = SceneManager._scene._spriteset.children;
const child = s[s.length - 1].children;
child[child.length].destroy();
or
JavaScript:
const s = SceneManager._scene._spriteset.children;
const child = s[s.length - 1].children;
child[child.length - 1].bitmap.clearRect(0,0,200,200);
With this code, you need to do length - 2, and then length - 3...until you cycle through everything. Doing it with a loop will just do it all at once, even in reverse. It will be too quick for the player to see it happening in reverse (unless you set up some wait times inside an event, and that is a whole other conversation).

It becomes harder to deal with because you can't always keep track of what you added and you add more guesswork to your workload. Destroy() might be better if you know you aren't going to use that bitmap anymore.

To be able to draw on the same bitmap, as I stated earlier, you have to find that bitmap and then reference the context.

Let's say you use the script above which created a new container and a new bitmap with the house. You then cleared it (not destroy) and you want to draw something else on it - you need to find that specific container and bitmap before you can draw on it .

In this example, I know that the last child I added is the container and the last child I added to the container is the house so I just need to do .length - 1 for each of them:
JavaScript:
const s = SceneManager._scene._spriteset.children;
const child = s[s.length - 1].children;
const bitmap = child[child.length - 1].bitmap;
const ctx = bitmap._context;
ctx.strokeStyle = 'red';
ctx.fillStyle = 'blue';
ctx.strokeRect(0, 0, 200, 200);
ctx.fillRect(100, 200, 200, 300);
bitmap._setDirty();
Doing it like this allows me to reference that specific bitmap to add more things to it. Again, this is ASSUMING that it was the last thing you added to the scene. Otherwise, you have to search for it (use the console to look at the array of children and go from there).

Hope this helps! Anything else will have to come from experimenting because I don't know your true goals and what you are after and everything that you do. You need to adapt to it - the code above won't work if you add new children to the scene (which is why I name everything).

And even then, if you add more, you need to be ready to work with more and also be ready to find out where everything is located.

Happy hunting!
I have tested some of yours script and I have some errors:
cannot read property '_context' of undefined
cannot read property 'destroy' of undefined
cannot read property 'clearRect' of undefined

It doesn't work so I cannot check if 'length' work as well

The problem is each time a use the script to draw I generate more 'container' child which they will generate more 'house' child. Then when I try to use clearRect, it will effectly work on the first child of SceneManager but after it still stuck in the first child array.
child.png

At first I was fixed about using clearRect to erase drawing in function of their location, but in reality if each drawings have their own layers I don't have to worry about to erase them locally when I can just destroy their array layers.

It's just a proposition but until now you have posted a way to clean 'house' child, but wouldn't be more efficient to destroy 'container' child instead?
One last thing: can you confirm if I destroy a child then the remaning arrays will rearrange themself?

Original thread: https://forums.rpgmakerweb.com/threads/display-tiles-grid.175982/