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

Status
Not open for further replies.

#### bishiba

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!

Last edited:

#### Eliaquim

##### Hakuen Studio
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()

myLine.position.set(path.x1, path.y1)
myLine.lineStyle(lineSize , color).moveTo(0, 0).lineTo(path.x2, path.y2)``````

#### bishiba

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()

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

#### slimmmeiske2

##### Little Red Riding Hood

Status
Not open for further replies.

### Latest Profile Posts

Hey, how did your emergency surgery go? Are you okay?
All aboard the Advent calendar train, riding Avery's coattails as an excuse to make more sprites.

Get 'em in my thread in General Resources.
I had a dream where it was Friday, and what happened in the dream was irrelevant, because I woke up and it's not Friday, so I'm sad.
wow I cannot brain today