我使用一些 jquery 和一个方便的在线教程创建了突破。
这是 fiddle :http://jsfiddle.net/Kinetic915/9bLEk/6/
我成功更改了访问窗口大小的宽度和高度,如下所示:
来自:
WIDTH = $("#canvas")[0].width = $(window).width();
HEIGHT = $("#canvas")[0].height = $(window).height();
致:
var WIDTH = document.getElementById("canvas");
var HEIGHT = document.getElementById("canvas");
WIDTH.width = window.innerWidth;
HEIGHT.height = window.innerHeight;
WIDTH = window.innerWidth;
HEIGHT = window.innerHeight;
代码正确加载。我发现更改渲染球的代码时出现问题。
它在这里与 jquery 一起使用:
Cir = $('#canvas')[0].getContext("2d");
Cir.beginPath();
Cir.arc(x, y, 10, 0, Math.PI * 2, true);
Cir.closePath();
Cir.fill();
不适用于:
var canvas = document.getElementById("canvas");
var Cir = canvas.getContext("2d");
Cir.beginPath();
Cir.arc(x, y, 10, 0, Math.PI * 2, true);
Cir.closePath();
Cir.fill();
有什么建议吗?
最佳答案
将其更改为:
var canvas = document.getElementById("canvas");
var Cir = canvas.get(0).getContext("2d");
关于javascript - 使用 jquery 创建了一个简单的 BREAKOUT 游戏,尝试转换回纯 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16426616/