lua - 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
函数将绘图模式作为它的第一个参数,其余(变量)参数是您要绘制的多边形顶点的坐标。由于您想绘制一个矩形,因此您需要四个顶点/八个数字。您不必首先列出矩形的左上角,但这可能是最简单的事情。
所以在你的情况下,你想要这样的东西:
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
。
推荐阅读
- teradata - teradata 中的正则表达式
- java - 将新列属性添加到 shapefile 并使用 Geotools Java 将其保存到数据库
- reactjs - Razorpay installation in react js
- delphi - Font.charset being changed to ANSI when loading files
- android - How to send Image from database to gallery android studio
- ruby-on-rails - how to access specific ActiveStorage image in multiple images
- ionic-framework - hello,how can i use (click)="{{}}" in ionic
- javascript - html 5拖放在移动屏幕上不起作用
- selenium - How to change already set chrome options while running tests?
- scala - how to do non blocking wait on a future for 10 seconds?