love.graphics.polygon 中的坐标是什么意思

What do the coordinates mean in love.graphics.polygon

我不知道在此处的坐标示例中哪些数字有什么作用。我想他们的意思是把左上角放在这个位置,把右下角放在这个位置,但我不知道哪个数字对应哪个位置。

我一直在尝试使用数字来获得一个绿色的小矩形,但不断得到如下奇怪的结果,并且不知道哪些数字需要按什么顺序才能使矩形对称并且在底部

矩形应该是这样的

矩形的高度为50,屏幕的高度为1000,屏幕的宽度为1700。

这是我的绘制函数

function love.draw()
  love.graphics.setColor(0.28, 0.63, 0.05) -- set the drawing color to green for the ground
  love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints())) -- draw a "filled in" polygon using the ground's coordinates
    --  These are the grounds coordinates.      -11650  950 13350   950 13350   1000    -11650  1000

  love.graphics.setColor(0.76, 0.18, 0.05) --set the drawing color to red for the ball
  love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())

  love.graphics.setColor(0.20, 0.20, 0.20) -- set the drawing color to grey for the blocks
  love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
  love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
  print(objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
end

https://love2d.org/wiki/love.graphics所述,Löve 的坐标系在屏幕的左上角有 (0, 0)。 X值向右增加,Y值向下增加。

polygon函数需要绘图模式作为它的第一个参数,其余(可变)参数是您要绘制的多边形顶点的坐标。由于要绘制矩形,因此需要四个 vertices/eight 数字。您不必首先列出矩形的左上角,但这可能是最简单的事情。

所以在你的情况下,你想要这样的东西:

love.graphics.polygon('fill', 0, 950, 0, 1000, 1700, 1000, 1700, 950)

我没有使用过物理系统,所以我不太确定它的坐标系与 "screen" 坐标的关系。您在代码清单的注释中显示的值似乎应该给出一个矩形(尽管 x = -11650 不会出现在屏幕上)。您可以先尝试在没有物理系统的情况下进行实验。

此外,由于 Löve 中的物理系统只是绑定到 Box2D,您可能需要阅读其文档 (http://box2d.org/about/)。不太确定将 shape:getPoints 输入 body:getWorldPoints.

是为了做什么