Hello, I would to know if there there are a way to display more that 1 drawing at the same time. I use this script but I unable to display more that 1 drawing:
The difficulty is I must be able to drawing everywhere on the map in function of their coordinates, and there are a possibility to draw the same or a different one so I cannot just create a script for each possibilties.
At first I used PIXI graphics, but I had some difficulty to clear drawings.
With "SceneManager._scene._spriteset.getChildByName('graph').destroy()" I could only erase them one by one (from the first to the last whereas it will be more convienent if it was from the last to the first) and of course no possibility to erase all them in one go.
So now I try with canvas ctx because I can clear drawings locally with "ctx.clearRect(x, y, width, height)", it's really more flexible to erase drawings in function of coordinates contrary to PIXI graphics. This the scrip I was used with Pixi graphics:
So if you have an idea about how I can draw more that one time with canvas ctx OR if you know how to clear drawings locally with xy coordinate in using PIXI graphics, it's will be a great help.
JavaScript:
const c = document.getElementById("myCanvas");
const ctx = c.getContext('2d');
const path = new Path2D();
c.setAttribute('width', x));
c.setAttribute('height', y);
ctx.lineWidth = 10;
ctx.strokeStyle = 'color';
ctx.beginPath();
ctx.moveTo(($gameVariables.value(x)*48+X), ($gameVariables.value(y)*48+Y));
ctx.lineTo(($gameVariables.value(x)*48+X), ($gameVariables.value(y)*48+Y));
.
.
.
ctx.closePath();
ctx.stroke();
const spr = new PIXI.Sprite.from(c);
SceneManager._scene._spriteset.addChild(spr);
The difficulty is I must be able to drawing everywhere on the map in function of their coordinates, and there are a possibility to draw the same or a different one so I cannot just create a script for each possibilties.
At first I used PIXI graphics, but I had some difficulty to clear drawings.
With "SceneManager._scene._spriteset.getChildByName('graph').destroy()" I could only erase them one by one (from the first to the last whereas it will be more convienent if it was from the last to the first) and of course no possibility to erase all them in one go.
So now I try with canvas ctx because I can clear drawings locally with "ctx.clearRect(x, y, width, height)", it's really more flexible to erase drawings in function of coordinates contrary to PIXI graphics. This the scrip I was used with Pixi graphics:
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(($gameVariables.value(x)*48+X), ($gameVariables.value(y)*48+Y))
.lineTo(($gameVariables.value(x)*48+X), ($gameVariables.value(y)*48+Y))
.
.
.
b.name = 'bars'; g.addChild(b);
So if you have an idea about how I can draw more that one time with canvas ctx OR if you know how to clear drawings locally with xy coordinate in using PIXI graphics, it's will be a great help.