【问题标题】:What do the coordinates mean in love.graphics.polygonlove.graphics.polygon 中的坐标是什么意思
【发布时间】:2018-05-24 09:38:38
【问题描述】:

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

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

矩形应该是这样的

矩形的高度是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

【问题讨论】:

    标签: lua love2d


    【解决方案1】:

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

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 2017-06-11
      • 2018-03-05
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多