Преглед изворни кода

code refactoring and adding meta viewport to html header

laira пре 3 година
родитељ
комит
bc42cf7919
3 измењених фајлова са 6 додато и 23 уклоњено
  1. 4 15
      index.html
  2. 2 2
      js/gameMechanics.js
  3. 0 6
      js/globals.js

+ 4 - 15
index.html

@@ -6,6 +6,7 @@
 <head>
 
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+	<meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="description" content="Educational game for teaching fractions" />
   <meta name="keywords" content="ifractions, fraction, game, private data" />
   <link rel="shortcut icon" href="assets/img/scene/flag.png">
@@ -13,11 +14,6 @@
   <link rel="stylesheet" href="css/bootstrap.min.css">
 
   <style>
-    /*
-    body, .panel-body {
-      background-color: #313857;
-    }
-    */
     #iFractions-canvas {
       padding: 0 auto 0 auto;
       margin-left: auto;
@@ -105,13 +101,8 @@
 
   <div class="container">
 
-    <div class="clearfix">
-    </div>
-
     <div class="panel panel-primary">
-
       <div class="panel-heading">iFractions game :: by LInE</div>
-
       <div class="panel-body">
 
         <canvas id="iFractions-canvas"></canvas> <!-- iFractions game -->
@@ -149,11 +140,9 @@
       const defaultWidth = 900; // Default width for the Canvas
       const defaultHeight = 600; // Default height for the Canvas
 
-      canvas = document.getElementById("iFractions-canvas");
-      canvas.width = defaultWidth;
-      canvas.height = defaultHeight;
-
-      const context = canvas.getContext("2d");
+      const context = document.getElementById("iFractions-canvas").getContext("2d");
+      context.canvas.width = defaultWidth;
+      context.canvas.height = defaultHeight;
 
       // CREATING GAME STATES
       game.state.add('boot', bootState);

+ 2 - 2
js/gameMechanics.js

@@ -1005,14 +1005,14 @@ const game = {
      * @param {function} func function to be called when event is triggered
      */
     add: function (name, func) {
-      canvas.addEventListener(name, func);
+      context.canvas.addEventListener(name, func);
       game.event.list.push([name, func]);
     },
     /** [Not directly used] Clears list of events. Called before moving to new state.
      */
     clear: function () {
       game.event.list.forEach(cur => {
-        canvas.removeEventListener(cur[0], cur[1]);
+        context.canvas.removeEventListener(cur[0], cur[1]);
       });
       game.event.list = [];
     },

+ 0 - 6
js/globals.js

@@ -45,12 +45,6 @@ const debugMode = false;
  */
 const moodle = false;
 
-/**
- * HTMLCanvasElement : Canvas where all the game elements are rendered.
- * @type {object}
- */
-let canvas;
-
 /**
  * Name of the selected game.<br>
  * Can be: 'squareOne', 'squareTwo' or 'circleOne'.