Created
October 24, 2016 17:15
-
-
Save raduGaspar/88aff5cb5bccf133747944c2e2dab03f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Keyboard } from '../'; | |
| let canvasInstance; | |
| class CanvasSingleton { | |
| constructor() { | |
| if(!canvasInstance) { | |
| console.log('Canvas instance created'); | |
| let canv = document.createElement('canvas'); | |
| this.canvas = canv; | |
| this.ctx = canv.getContext('2d'); | |
| document.body.appendChild(canv); | |
| window.addEventListener('resize', this.resize.bind(this)); | |
| this.resize(); | |
| canvasInstance = this; | |
| } | |
| return canvasInstance; | |
| } | |
| resize() { | |
| this.canvas.width = window.innerWidth; | |
| this.canvas.height = window.innerHeight; | |
| } | |
| }; | |
| export default class Canvas extends Keyboard { | |
| constructor() { | |
| super(); | |
| canvasInstance = new CanvasSingleton(); | |
| this.canvas = canvasInstance.canvas; | |
| this.ctx = canvasInstance.ctx; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment