Display Tiles Grid

Hello, I make a board game where you put on the field pieces with a specific form. I manage this in using self-switch, but when I put many piece together I not be able to recognize anymore which form I have already use, so I'm wonder if there are a way to display the grid of specific tiles.

board.png
piece.png
piece-border.png


I guess is possible to do with css, but I don't know how work css on javascript, do use a class attribute like in html? How can I link my script to css?
After if someone have a other way that using css it's welcome.
There are plugins that make a color overlay over tiles of x region. You can also use a tile changing plugin like Shaz's

There are plugins that make a color overlay over tiles of x region. You can also use a tile changing plugin like Shaz's

None of these will work.
SAN_TileToner and Tile changer change tiles , I don't if I wasn't sufficiently accurate but my problem isn't to change tiles but to display their border, and I mean their border top, bottom, left or right in function of what I want to show. So as I proposed earlier I think it's possible in using css
You can just use events put them under the player and over those grids.
@fenri734
then you need to tell us how you create those pieces to place, because they are obviously not tiles as defined in the RPG Maker.

and no, I highly doubt that css can help here because the map doesn't use css at all, it creates a picture from partial references in the tileset.
@fenri734
then you need to tell us how you create those pieces to place, because they are obviously not tiles as defined in the RPG Maker.
To create those pieces I use a script call which will activate multiple events self-switch (as I have already mentioned in the first post)
as I have already mentioned in the first post
and your answer is not what I asked for.

If I see the first post correctly, then each of your pieces consist of four tiles in different forms like tetris pieces.

THAT is what I meant with "piece", so how exactly do you place one of those pieces?
With details as in every command you used.

Because if you used the shortcut I think you used, then your answer is "Impossible, because the computer cannot read your mind to get the missing information"
and your answer is not what I asked for.

If I see the first post correctly, then each of your pieces consist of four tiles in different forms like tetris pieces.

THAT is what I meant with "piece", so how exactly do you place one of those pieces?
With details as in every command you used.

Because if you used the shortcut I think you used, then your answer is "Impossible, because the computer cannot read your mind to get the missing information"
the tetris form is just an example, and I will repeat me again: I use script to activate self-switch events to generate pieces
JavaScript:
var key = [MapId, $gameMap.eventIdXy($gameVariables.value(x),$gameVariables.value(y)), 'switch'];
$gameSelfSwitches.setValue(key, true);

But apparently it's not possible to apply css code on events.
So in my case it would be possible to use javascript to draw horizontal or vertical lines in function of their location (x,y), and give to them a class attribute.
In this way, the css can work (I must draw to much lines so if I must manage their style one at once I will be very annoyed)
Ok guys a find a way to do it thanks to this tread:

https://forums.rpgmakerweb.com/index.php?threads/can-i-use-javascript-to-draw-a-graph.175848/

JavaScript:
const s = SceneManager._scene._spriteset;
const g = new PIXI.Graphics()
 g.name = 'graph';
  s.addChild(g);
 const b = new PIXI.Graphics()
 .lineStyle(size, color)
 .moveTo(origin x,origin y)
 .lineTo(end x,end y)
b.name = 'bars';
g.addChild(b);

these is for drawing border in function of a coordinate xy
JavaScript:
 .moveTo(($gameVariables.value(x)*48),($gameVariables.value(y)*48)) .lineTo(($gameVariables.value(x)*48+48),($gameVariables.value(y)*48))        //top border
 .moveTo(($gameVariables.value(x)*48+1),($gameVariables.value(y)*48)) .lineTo(($gameVariables.value(x)*48),($gameVariables.value(y)*48+48))        //left border
 .moveTo(($gameVariables.value(x)*48),($gameVariables.value(y)*48+47)) .lineTo(($gameVariables.value(x)*48+48),($gameVariables.value(y)*48+48))    //bottom border
 .moveTo(($gameVariables.value(x)*48+48),($gameVariables.value(y)*48)) .lineTo(($gameVariables.value(x)*48+48),($gameVariables.value(y)*48+48))    //right border

Technically it's work but I would prefered to find a way to apply css to all the drawing lines.

Then I work also on a debbug menu so I wonder if there is a way to delete a specific drawing line at a location xy, and also how erase all drawing lines at the same times (in case where I want to run a new game)
I am not sure if this is compatible, but you are welcome to try it:
If you are looking to do it yourself, I would draw the border with .drawRect(x, y, width, height) where x/y is the starting point and width/height is, well, the wdith and height of your rectangle.

Every child (or new child) that you create must be referenced by their own id or by a name that you designate.

When you use .clear(), it only clears the contents of that specific child.

Using .destroy() will remove the contents as well as the object which means you have to create a new graphic.

If you use the same name for several children in your scene, it will try to look for the first one it can find and only return that, assuming you are looking in the correct property/object.

Be sure to remember where you place them and if you are naming them, remember to give them unique names/ids.

Otherwise, they are stored as an array, typically under the .children property (in the order that it was added).
I am not sure if this is compatible, but you are welcome to try it:
If you are looking to do it yourself, I would draw the border with .drawRect(x, y, width, height) where x/y is the starting point and width/height is, well, the wdith and height of your rectangle.

Every child (or new child) that you create must be referenced by their own id or by a name that you designate.

When you use .clear(), it only clears the contents of that specific child.

Using .destroy() will remove the contents as well as the object which means you have to create a new graphic.

If you use the same name for several children in your scene, it will try to look for the first one it can find and only return that, assuming you are looking in the correct property/object.

Be sure to remember where you place them and if you are naming them, remember to give them unique names/ids.

Otherwise, they are stored as an array, typically under the .children property (in the order that it was added).
I don't think pixijs-grid will work, apparently it only display grid when I only need to display line.

Is it possible to have a .drawRect() but with .destroy()? I mean can I define a rectangle where all contents inside will be removed?
Because if I want to clear all drawing I just need to create a rectangle big enought, and if I want to clear contents on 1 tiles I can juste create a rectangle 48px*48px at a coordinate xy
Is it possible to have a .drawRect() but with .destroy()?
You should be able to use .clear() to clear the drawing or .destroy() to delete/remove the object.
You should be able to use .clear() to clear the drawing or .destroy() to delete/remove the object.
The problem isn't .clear()/.destroy(), but it only remove child drawing whereas I have many draw I want to remove.
I precize but I have many drawing and they aren't created at the same time.
The problem isn't .clear()/.destroy(), but it only remove child drawing whereas I have many draw I want to remove.
I precize but I have many drawing and they aren't created at the same time.
That means you have to be able to find the child specifically that you add.

So if you added a new graphic at SceneManager._scene._spriteset, you have to reference it first before you can clear/destroy.

Let's say you added 3 graphics. In order to find them easier, you have to name them. For this example, we will call them 'graph1', 'graph2', and 'graph3'. All three are added to the spriteset.

To find and clear/destroy a specific graph, you need to find it with the getChildByName() function. So, to get graph2 inside of spriteset and clear it without touching graph1 or graph3, we do:
JavaScript:
SceneManager._scene._spriteset.getChildByName('graph2').clear();
It is important that you either know where they are added as a child or name them so you can use the function above to get them. Again, naming them with the same name will make it much harder to organize.

Unless I am misunderstanding what you are after?

When dealing with all these graphics, I like to put then into a texture so I can create a sprite and deal with them from there as a set. But that is another part of PIXI that you will need to explore (there are also containers as well which are display objects that can hold the sprites, etc.).

I do recommend checking the PIXI.js documentation for your specific version since it can be much more helpful to test and run things yourself.
SceneManager._scene._spriteset.getChildByName('graph2').clear();
Ok it's work but it remove them one by one each time I activate the script (from the first to the last). XD

Then, is there a way to clear absolutely all drawings?
Ok it's work but it remove them one by one each time I activate the script (from the last to the first). XD

Then, is there a way to clear absolutely all drawings?
If they are all under one child, then yes. You can do:
JavaScript:
const g = new PIXI.Graphics()
  .beginFill(0x000000)
  .drawCircle(0,0,100)
  .endFill();
SceneManager._scene._spriteset.addChild(g);
g.name('test1');
const h =
new PIXI.Graphics()
  .beginFill(0xffffff)
  .drawCircle(100,100,100)
  .endFill();
g.addChild(h);  // Add the child to g instead of spriteset
By adding the other child to g which is named 'test' ('test1'), you can delete g and it will delete everything under it.
JavaScript:
SceneManager._scene._spriteset.getChildByName('test1').destroy()
If they are all under one child, then yes. You can do:
JavaScript:
const g = new PIXI.Graphics()
  .beginFill(0x000000)
  .drawCircle(0,0,100)
  .endFill();
SceneManager._scene._spriteset.addChild(g);
g.name('test1');
const h =
new PIXI.Graphics()
  .beginFill(0xffffff)
  .drawCircle(100,100,100)
  .endFill();
g.addChild(h);  // Add the child to g instead of spriteset
By adding the other child to g which is named 'test', you can delete g and it will delete everything under it.
JavaScript:
SceneManager._scene._spriteset.getChildByName('test1').destroy()
It doesn't work, it delete them only one by one, and only from the first to the last whereas it would be less problematic if it was from the last to the first.

But there isn't a way to delete them in using a rectangle to have a control on what I want to clear?
It doesn't work, it delete them only one by one, and only from the first to the last whereas it would be less problematic if it was from the last to the first.

But there isn't a way to delete them in using a rectangle to have a control on what I want to clear?
I am not sure if we are doing the same thing. By putting them under one child, you can delete them all at once went you delete that specific child, not one by one.

I am not sure I understand what you mean by using a rectangle - are you referring to changing the image data of a specific area for a bitmap (which is different from a graphic), creating a mask to block off a certain part of the graphic, or something else?

Currently, the way I showed you, when I destroy the child holding the other children, it erases everything all at once, not one at a time. If you can show your code, it will help us from all the guesswork. Thanks!
I am not sure if we are doing the same thing. By putting them under one child, you can delete them all at once went you delete that specific child, not one by one.

I am not sure I understand what you mean by using a rectangle - are you referring to changing the image data of a specific area for a bitmap (which is different from a graphic), creating a mask to block off a certain part of the graphic, or something else?

Currently, the way I showed you, when I destroy the child holding the other children, it erases everything all at once, not one at a time. If you can show your code, it will help us from all the guesswork. Thanks!

I make a board game where you put pieces on the board (I manage that with self-switches) and for recognize each pieces I use this:
JavaScript:
const s = SceneManager._scene._spriteset;
const g = new PIXI.Graphics();
g.name = 'graph';
s.addChild(g);
const b = new PIXI.Graphics()
 .lineStyle(1, 0x0000ff)
 .moveTo(x,y)
 .lineTo(x,y)
      .
      .
      .
b.name = 'bars';
g.addChild(b);

And for now I use this to remove them (but it's work from the first to the last)
JavaScript:
const g = SceneManager._scene._spriteset.getChildByName('graph').destroy()
I must be misunderstanding your issue then because there is no sequence (first to last, or last to first) of removing items on my end. When I remove the parent, all the children are gone simultaneously.

One possible issue I can think of is that you are creating a new pixi graphic each time you run this code (or if you have it in a loop), causing several layers of the same name to be created to where you have to remove each one individually until they are all gone.

Maybe someone else with a different perspective can help.

Sorry about that. Hope it all goes well for you!

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