- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的游戏中有一些代码可以在其 Canvas 中旋转图标,如下所示:
if (rotate > 0) {
context.translate(canvasWidth / 2, canvasHeight / 2);
context.rotate(rotate);
context.translate(-canvasWidth / 2, -canvasHeight / 2);
}
var x = 0;
var y = 0;
for (var i = 0; i < totalUnits; i++) {
context.drawImage(img, x, y);
if (i != 0 && (i + 1) % level == 0) {
x = 0;
y += 72;
}
else {
x += 72;
}
}
level
可以是任意整数,
totalUnits
如果它大于 1,则是它的平方,例如,如果我指定
level
作为 2,然后在我的 Canvas 上绘制了 4 个图像,2 个横向和 2 个向下。另请注意,我的图像始终为 72x72 像素,因此是上面的 72。同样,没有什么特别令人兴奋的。
rotate
中传递的值旋转单个图像。 ,但不是整个 Canvas 本身。我尝试添加以下代码,其中包含许多排列替换上述对
context.drawImage
的调用在
for
循环,到目前为止没有运气:
context.translate(72 / 2, 72 / 2);
context.rotate(rotate);
context.drawImage(img, x, y);
context.rotate(0);
context.translate(-72 / 2, -72 / 2);
最佳答案
最简单的方法是覆盖当前的转换
ctx.setTransform(scale, 0, 0, scale, x, y);
ctx.rotate(rotate);
ctx.drawImage(img, -img.width / 2, -img.height/ 2);
x
绘制图像中心,
y
,旋转了
rotate
附近
img
居中,按
scale
缩放. 1 的规模是没有规模。
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.rotate
至少需要 1 个 sin 和 1 个 cos,12 个临时数字,然后是 12 个乘法和 8 个加法。如果缩放是统一的(x 和 y 的缩放相同),则使用简化的方法来创建矩阵会更快。请注意,如果比例始终为 1,则不需要比例`
img.offset_x = - img.naturalWidth / 2; // NOTE I use snake_case for the property names
img.offset_y = - img.naturalHeight / 2; // so that the names will never clash with
// future changes to the standard
const ax = Math.cos(rotate) * scale;
const ay = Math.sin(rotate) * scale;
ctx.setTranform(ax, ay, -ay, ax, x, y);
ctx.drawImage(img, img.offset_x, img.offset_y);
关于javascript - 在 HTML Canvas 中单独旋转平铺图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59852447/
我正在尝试制作一种能够解决拼贴问题中的大图 block 集的算法。现在它能够根据宽度和高度找到正确的 Tiles 来放置,但是在使其正确递归方面存在一些问题。 如您所见,这个想法是,在放置的每个图 b
有什么方法可以轻松地平铺 mdi parent 的所有表单 child 吗?我正在寻找 windows 提供的大部分功能,瓷砖级联。有谁知道一个简单的方法? 最佳答案 试试这些... // Tile
我有一个大 jpg,其分辨率为 x * 256/x * 256。我想将此图像切割为 256x256 的图块,命名约定为 {zoom}-{x}-{y}.jpg。过去我使用 ZoomifyExpress
如何使用ImageMagick平铺图像?我认为我不能使用montage,因为我希望将列偏移原始图像高度的50%。 展示我正在尝试做的事可能更容易: 从...开始: 结尾为: 谢谢! 最佳答案 感谢Fr
是否可以在 XNA 中平铺图像以使其填满整个矩形?我试过用谷歌搜索这个主题,但我找不到任何似乎有用的东西(虽然我可能遗漏了一些明显的东西)。我找到了 this MSDN page ,但我似乎无法让它工
我无法找到答案,为什么我为图 block map 制作的图 block 表在使用 libGDX 在屏幕上移动时会创建垂直白线和不稳定的水平线。 这是显示白色垂直线的视频:https://www.you
有谁知道 GitHub Java version of Tiled 中如何临时支持视差图层吗?工作正常吗? 它可以编译,并且执行得很好。但是,如果我将图层设置为viewplane distance 0
在我制作的平台游戏中,我需要加载图 block 才能创建关卡,但在下面的代码中我似乎遇到了问题。它说我在这部分有一个错误: String[] skips = skip.split(" "); 但对我来
使用 pdfimages 提取图像和 mupdf/mutool到目前为止工作正常。 使用 FreePDF 生成的 PDF 中的图像总是被切片,因此一个图像会生成多个图像文件。 有什么技巧可以避免这种情
我正在尝试使用 Tiled 编写基于 rts-like-tile 的游戏和 slick2d。 我不知道如何处理多图 block 对象,例如建筑物,如何创建、保存等等。移动它们。 最佳答案 一种解决方案
我想用一张图片来编写一个平铺 map 。它应该是一个 5x5 的小图片区域。我写了一些带有 2 个嵌套循环的 Javascript 代码。使用此解决方案,仅打印 1 张图片。当我在第二个循环中删除 b
我正在尝试使用 Slick2D 和 Tiled Map Editor 制作一个基本的 2D 游戏。我已经弄清楚如何使用 TileProperties 进行基本的碰撞检测,但我不确定对象如何与 map
我正在尝试创建一个无限滚动的分页 UIScrollView 我一直在关注 Advanced UIScrollView Techniques来自 WWDC 2010 的视频,但是我不确定如何为分页 UI
好吧,假设我有一个像本网站一样的冷却平铺背景。 http://www.leeslights.com/colors-shapes-sizes-and-prices.html 我将如何使图像平铺到浏览器,
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
我是一名优秀的程序员,十分优秀!