From f05279bc220d20ed8b4c493085e4c7c34ed4f500 Mon Sep 17 00:00:00 2001 From: Sergey Nikolaev Date: Fri, 14 Oct 2022 17:20:24 +0300 Subject: [PATCH] retina-friendly now --- center.js | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/center.js b/center.js index 09e69b4..19612e9 100644 --- a/center.js +++ b/center.js @@ -1,11 +1,11 @@ /*! - * The Center Game v.0.1 - * Description: https://github.com/kefiijrw/The-Center-Game + * The Center Game v.1.1 + * https://github.com/kefiijrw/The-Center-Game * * Author: Sergey Nikolaev * kefiijrw.com * - * Date: 2022-09-26 + * Date: 2022-10-14 */ var min_angle = 5; @@ -28,20 +28,35 @@ var mode = 2; var round_count = 5; var score_limit = 40; +dpr = window.devicePixelRatio || 1; + var canvas_t = document.getElementById('canvas_top'); var canvas_b = document.getElementById('canvas_bottom'); var canvas_c = document.getElementById('canvas_circle'); + var c_b = canvas_b.getContext('2d'); var c_t = canvas_t.getContext('2d'); var c_c = canvas_c.getContext('2d'); -c_b.canvas.width = window.innerWidth; -c_b.canvas.height = window.innerHeight; -c_t.canvas.width = window.innerWidth; -c_t.canvas.height = window.innerHeight; -c_c.canvas.width = window.innerWidth; -c_c.canvas.height = window.innerHeight; +c_b.canvas.width = window.innerWidth*dpr; +c_b.canvas.height = window.innerHeight*dpr; +c_t.canvas.width = window.innerWidth*dpr; +c_t.canvas.height = window.innerHeight*dpr; +c_c.canvas.width = window.innerWidth*dpr; +c_c.canvas.height = window.innerHeight*dpr; + +c_b.scale(dpr, dpr); +c_t.scale(dpr, dpr); +c_c.scale(dpr, dpr); + +c_b.canvas.style.width = window.innerWidth + 'px'; +c_b.canvas.style.height = window.innerHeight + 'px'; +c_t.canvas.style.width = window.innerWidth + 'px'; +c_t.canvas.style.height = window.innerHeight + 'px'; +c_c.canvas.style.width = window.innerWidth + 'px'; +c_c.canvas.style.height = window.innerHeight + 'px'; + var score; @@ -50,6 +65,15 @@ var score_speed = 10; + + + + + + + + + function draw_question() { c_b.clearRect(0, 0, canvas_b.width, canvas_b.height); @@ -89,8 +113,8 @@ function draw_question() { - c_t.canvas.width = window.innerWidth; - c_t.canvas.height = window.innerHeight; + // c_t.canvas.width = window.innerWidth; + // c_t.canvas.height = window.innerHeight; c_t.beginPath(); @@ -253,4 +277,4 @@ document.addEventListener('click', function (event) { } -}); \ No newline at end of file +});