又一部被弃用的戏剧。我在 javascript 上创建俄罗斯方 block 游戏,但在尝试在 Canvas 上绘制时不断出现以下错误:
Use of mozImageSmoothingEnabled is deprecated. Please use the unprefixed imageSmoothingEnabled property instead.
但我不知道如何使用无前缀形式!我怎样才能使这项工作? 我可以看到绘制的 Canvas ,但无论我做什么,作品都不会显示。
这是我在名为 view.js 的文件中的代码:
export default class View {
constructor(element, width, height, rows, columns) {
this.element = element;
this.width = width;
this.height = height;
this.canvas = document.createElement('canvas');
this.canvas.width = this.width;
this.canvas.height = this.height;
this.context = this.canvas.getContext('2d');
this.blockWidth = this.width / columns;
this.blockHeight = this.height / rows;
this.element.appendChild(this.canvas);
}
renderPlayfield(playfield) {
for (let y = 0; y < playfield.length; y++) {
const line = playfield[y];
for (let x = 0; x < line.height; x++) {
if (block) {
this.context.fillStyle = 'white';
this.context.strokeStyle = 'black';
this.context.lineWidth = 2;
this.context.fillRect(x * this.blockWidth, y * this.blockHeight, this.blockWidth, this.blockHeight);
}
}
}
}
}
然后在我的 index.js 上我有:
import Game from './src/game.js';
import View from './src/view.js';
const root = document.querySelector('#root');
const game = new Game();
const view = new View(root, 480, 640, 20, 10);
window.game = game;
window.view = view;
view.renderPlayfield(game.playfield);
最佳答案
在使用 Firefox Developer Edition 89.0b10 进行调试时我遇到了同样的情况 - 在请求 Canvas 上下文后弹出警告:
var ctx = self.ctx = can.getContext("2d");
看起来像是一个小的 Firefox 内部配置错误。除此之外,Firefox 仍然是我所知道的最好的浏览器。
关于javascript - 不推荐使用 mozImageSmoothingEnabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62221791/