简体   繁体   English

使用图像渲染:像素化; 导致运动图像波纹垂直像素线

[英]Using image-rendering: pixelated; causes moving image to ripple a vertical pixel line

I'm attempting to create a simple javascript canvas game in a desktop app using an electron.我正在尝试使用电子在桌面应用程序中创建一个简单的 javascript 画布游戏。 I'm using pixel art, so in order to keep my pixel art images to stay in good quality as they scale, I am using the following CSS:我正在使用像素艺术,所以为了让我的像素艺术图像在缩放时保持良好的质量,我使用了以下 CSS:

canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

Unfortunately, as the player controls the main sprite to make it move left and right, a strange ripple effect shifts a line through the sprite as it moves.不幸的是,当玩家控制主精灵使其左右移动时,一个奇怪的涟漪效应会在精灵移动时移动一条穿过精灵的线。 Example: https://imgur.com/a/MUCjv4W示例: https : //imgur.com/a/MUCjv4W

If I only use crisp-edges, this problem is fixed, but obviously a lot of quality is lost from the art.如果我只使用清晰的边缘,这个问题是固定的,但显然艺术中失去了很多质量。

Is there anything I can do to prevent this effect and just keep each pixel in its correct place?我能做些什么来防止这种效果并将每个像素保持在正确的位置?

If you use this line of JavaScript, you should be able to remove all of that CSS.如果您使用这行 JavaScript,您应该能够删除所有这些 CSS。 This will disable the smooth upscaling of images and keep the pixelated quality.这将禁用图像的平滑放大并保持像素化质量。

Replace context with your 2D canvas context.更换context与2D画布背景。

context.imageSmoothingEnabled = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM