MZ How would you draw a line from (x1;y1) to (x2;y2)? (SOLVED)

Hello all good people!

I am curious as to how to draw a simple colored line between coordinates x1,y1 to x2,y2.

Best regards,
Bishiba

Edit, solved:
Thanks to Eliaquim for solving this question. The code works on relative terms where x2, y2 are relative to the x1, y1. To correct for this you can use the below functions for x and y respectivly.


JavaScript:
BISH.distX = function(originId, destId) {
    return destId.x - originId.x;
}

BISH.distY = function(originId, destId) {
    return destId.y - originId.y;
}

Then you change Eliaquim's code to:
JavaScript:
const path = {x1: 300, y1: 300, x2: BISH.distX(originId, destId), y2: BISH.distY(originId, destId)}

Thank you!
I would go with something like that:

JavaScript:
const path = {x1: 300, y1: 300, x2: 700, y2: 500}
const lineSize = 10
const color = 0xffffff // White
const myLine = new PIXI.Graphics()


SceneManager._scene.addChild(myLine)
myLine.position.set(path.x1, path.y1)
myLine.lineStyle(lineSize , color).moveTo(0, 0).lineTo(path.x2, path.y2)
I would go with something like that:

JavaScript:
const path = {x1: 300, y1: 300, x2: 700, y2: 500}
const lineSize = 10
const color = 0xffffff // White
const myLine = new PIXI.Graphics()


SceneManager._scene.addChild(myLine)
myLine.position.set(path.x1, path.y1)
myLine.lineStyle(lineSize , color).moveTo(0, 0).lineTo(path.x2, path.y2)
Thanks mate, was a bit tricky at first since I did not think it would be drawn relatively to the origin point. But once I noted it it was an easy fix. Thanks mate 🙂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-would-you-draw-a-line-from-x1-y1-to-x2-y2-solved.138472/