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