Advertisement
Guest User

javascript canvas

a guest
Jun 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // javascript
  2. /*global
  3. alert, confirm, console, Debug, opera, prompt, WSH, strict
  4. */
  5. var canvas = document.getElementById("canvas"),
  6. context = canvas.getContext("2d"),
  7. width = window.innerWidth,
  8. height = window.innerHeight,
  9. ratio = window.devicePixelRatio;
  10. canvas.width = width * ratio;
  11. canvas.height = height * ratio;
  12. canvas.style.width = width + "px";
  13. canvas.style.height = height + "px";
  14. context.scale(ratio, ratio);
  15.  
  16.  
  17. document.addEventListener('keydown', function (e) {
  18.  
  19. "use strict";
  20. if (e.keyCode === 'D'.charCodeAt(0)) {
  21. alert("right");
  22.  
  23. } else if (e.keyCode === 'A'.charCodeAt(0)) {
  24. alert("left");
  25.  
  26. } else if (e.keyCode === 'W'.charCodeAt(0)) {
  27. alert("up");
  28.  
  29. } else if (e.keyCode === 'S'.charCodeAt(0)) {
  30. alert("down");
  31.  
  32.  
  33.  
  34.  
  35. }
  36. });
  37.  
  38. // html
  39. <!DOCTYPE html>
  40. <html>
  41. <head>
  42. <meta charset="utf-8"/>
  43. <title>CHANGE HISTORY</title>
  44. </head>
  45. <body style="margin: 0px; overflow: hidden">
  46.  
  47. <canvas id="canvas"></canvas>
  48.  
  49. <script type="text/javascript" src="main%20(2).lnk"></script>
  50.  
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement