Status
Not open for further replies.

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
227
Reaction score
129
First Language
Swedish
Primarily Uses
N/A
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
Veteran
Joined
May 22, 2018
Messages
2,290
Reaction score
1,787
First Language
Portuguese - Br
Primarily Uses
RMMZ
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)
 

bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
227
Reaction score
129
First Language
Swedish
Primarily Uses
N/A
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 :)
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,112
Reaction score
5,964
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Avery wrote on BCj's profile.
Hey, how did your emergency surgery go? Are you okay?
Remember when people had the ability to have meaningful conversations on platforms like twitter or facebook? Good times... Nowadays is absolute crap.
All aboard the Advent calendar train, riding Avery's coattails as an excuse to make more sprites. ;)
Advent2021-01.gif

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.

Forum statistics

Threads
117,098
Messages
1,104,555
Members
153,112
Latest member
Soohwa
Top