Added Line

This commit is contained in:
Arne van Iterson 2020-08-04 15:07:48 +02:00
parent c7a5df7923
commit bbe0923523
3 changed files with 16 additions and 0 deletions

9
lib/Line.js Normal file
View File

@ -0,0 +1,9 @@
class Line {
constructor(x1, y1, x2, y2, style = "#000000") {
this.pos = { x: x1, y: y1 };
this.target = { x: x2, y: y2 };
this.style = style;
}
}
module.exports = Line;

View File

@ -10,6 +10,7 @@ var AnimManager = require("./AnimManager.js"),
State = require("./State.js"),
Sound = require("./sound/Sound.js"),
Rect = require("./Rect.js"),
Line = require("./Line.js"),
KeyControls = require("./controls/KeyControls.js"),
MouseControls = require("./controls/MouseControls.js"),
Sprite = require("./Sprite.js"),
@ -35,6 +36,7 @@ module.exports = {
State,
Sound,
Rect,
Line,
KeyControls,
MouseControls,
Sprite,

View File

@ -91,6 +91,11 @@ class CanvasRenderer {
ctx.fillStyle = gradient;
ctx.fill();
} else if (child.style && child.target) {
ctx.moveTo(0,0);
ctx.lineTo(child.target.x, child.target.y);
ctx.strokeStyle = child.style;
ctx.stroke();
}
// Handle children with children