屏幕大小的最大等轴测平铺

Max isometric tiles from screen size?

本文关键字:屏幕      更新时间:2023-09-26

我想知道是否有人知道一个javascript公式,它可以根据用户的屏幕大小计算在任何给定时间出现在用户屏幕上的瓷砖的最大数量。。。

例如:如果我们说屏幕大小是1200像素乘600像素,瓦片是64像素乘32像素。

在鸟瞰图中,这很容易计算,但等距有点让我更困惑,无法理解如何在代码中实现这样的计算。

有人知道如何计算吗?

假设您只计算完全适合的瓷砖(没有截止):

  var verticalCount = Math.floor(windowHeight / tileHeight);
  var horizontalCount = Math.floor(windowWidth / tileWidth);
  var totalCount = verticalCount * horizontalCount;

如果您还想计算部分适合(被窗口截断)的瓷砖,只需将上面的两个Math.floor实例都更改为Math.ceil即可。

如果你想用等距瓷砖而不是木板填充屏幕,并且不计算可以显示的半块瓷砖,那么公式应该是

var cols = Math.floor(windowWidth/tileWidth)
var rows = Math.floor(windowHeight/tileHeight) 
var totalCount = (rows * cols) + ((rows-1)*cols)

这将为您提供可容纳在该空间中的完整等轴测瓷砖的数量。