From bbe0923523d6fb30aa4aaa087ef1dd6b4e232483 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Tue, 4 Aug 2020 15:07:48 +0200 Subject: [PATCH] Added Line --- lib/Line.js | 9 +++++++++ lib/index.js | 2 ++ lib/renderer/CanvasRenderer.js | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 lib/Line.js diff --git a/lib/Line.js b/lib/Line.js new file mode 100644 index 0000000..f40651b --- /dev/null +++ b/lib/Line.js @@ -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; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index eb5557f..1722deb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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, diff --git a/lib/renderer/CanvasRenderer.js b/lib/renderer/CanvasRenderer.js index 0a91af3..22c2233 100644 --- a/lib/renderer/CanvasRenderer.js +++ b/lib/renderer/CanvasRenderer.js @@ -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