Ok I wil resume about the project:
I tried to draw line which correspond to tiles border. At first I used this but I had some issue to destroy more that 1 with : SceneManager._scene._spriteset.getChildByName('graph').destroy()
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(100,100))
.lineTo(200,200)
b.name = 'bars'; g.addChild(b);
Next I tried with canvas to finally go to a hybrid version with PIXI and canvas
JavaScript:
const c = document.createElement('canvas');
const ctx = c.getContext('2d');
c.setAttribute('width', 300);
c.setAttribute('height', 200);
ctx.lineWidth = 1;
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.moveTo(100, 200);
ctx.lineTo(100, 200);
ctx.closePath();
ctx.stroke();
const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(spr);
But with this method I could only display 1 drawing at once. With the Pixi method I could draw how many I wanted but couldn't delete more that 1 (the first I had drawed), but with the canvas way I could use clearRect to clear many at once: problem I couldn't draw more that 1 time.
So I looked for a way to draw PIXI elements and then convert them into canvas element to clear them.
JavaScript:
const s = SceneManager._scene._spriteset;
const w = 500, h = 500;
const container = new PIXI.Container();
s.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 = 1; ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.moveTo(100, 100);
ctx.lineTo(200, 200);
ctx.closePath(); ctx.stroke();
r.destroy({destroyBase: true});
bitmap._setDirty();
const spr = new Sprite(bitmap);
spr.name = 'house'; container.addChild(spr);
To clear them I used this:
JavaScript:
const s = SceneManager._scene._spriteset.getChildByName('container');
for (const child of s.children) {
child.bitmap.clearRect(0, 0, 200, 200);
}
But an other problem to add: each time I used the drawing script, it created each time a new array so whatever I tried to clear it work but it stucked at the first array.
Then I looked there was a way to merge/flat all the drawing to 1 layer (to not have to manage array) but it was outside of my knowledge.
So finally, I'm gone back to the square one and with my first script I have found to make it simpler:
JavaScript:
const s = SceneManager._scene._spriteset;
line = new PIXI.Graphics();
line.name = 'line'; s.addChild(line);
line.lineStyle(1,0x0000ff);
line.moveTo(100,100);
line.lineTo(200,200);
With this script I can do any number of drawing, and if I use:
JavaScript:
SceneManager._scene._spriteset.getChildByName('line').destroy()
All drawing are erase one by one (from the first to the last)
So next I'm will need to looking about the length of array to clear them in the reverse order. But I don't manage to use "getChildIndex" or "getChildAt" and do apply it "length -1" :
JavaScript:
SceneManager._scene._spriteset.getChildIndex().destroy()
SceneManager._scene._spriteset.getChildAt().destroy()
EDIT:
It finally done thanks to guy from here:
https://forums.rpgmakerweb.com/index.php?threads/destroy-child-array-in-reverse-order.176500/
Here the script:
JavaScript:
const s = SceneManager._scene._spriteset;
line = new PIXI.Graphics();
line.name = 'line'; s.addChild(line);
line.lineStyle(size, $gameVariables.value(color)[num]);
line.moveTo(x0,y0);
line.lineTo(x1,y1);
$gameVariables.setValue(crash, $gameVariables.value(crash) + 1)
◆Input Number:#z, x digit
◆If:Script:($gameVariables.value(z) > 0) && ($gameVariables.value(z) <= $gameVariables.value(crash))
JavaScript:
const s = SceneManager._scene._spriteset;
const line = s.children; line.reverse()
$gameVariables.setValue(z, $gameVariables.value(z) - 1)
SceneManager._scene._spriteset.getChildAt($gameVariables.value(z)).destroy()
line.reverse()
$gameVariables.setValue(crash, $gameVariables.value(crash) - 1)
And for clear all:
◆Label:loop
◆If:Script:$gameVariables.value(crash) > 0
JavaScript:
SceneManager._scene._spriteset.getChildByName('line').destroy()
$gameVariables.setValue(crash, $gameVariables.value(crash) - 1)
◆If:Script:$gameVariables.value(crash) > 0
◆Jump to Label:loop