javascript - 不推荐使用 mozImageSmoothingEnabled

标签 javascript image firefox deprecated smoothing

又一部被弃用的戏剧。我在 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/

相关文章:

javascript - 使用discord.js 找不到模块错误

javascript - 检测鼠标支持

javascript - 重新定义一个 jQuery 对话框按钮

javascript - 使用 AJAX 请求加载图像不起作用

image - 在 Magento 中添加管理配置选项卡图像

javascript - jQuery 函数中的全局变量?

image - 干预图像长宽比

css - @font-face 不适用于 FF4

jquery - 如何在 Firefox Scratchpad 中使用 jQuery?

html - 在 Firefox 中使用 css 转换时边框渲染不正确