0

我想把图片中的那个蓝色三角形放在我的红房子上。我一直在输入随机数,但我无法正确输入。问题出在 Gosu.draw_triangle 部分。人们说这个网站会帮助 https://www.rubydoc.info/github/gosu/gosu/master/Gosu.draw_triangle 但我没有从中得到任何好处。

图片

def initialize 
 def initialize
    super(800, 600, false)
  end

  def draw
    Gosu.draw_rect(310, 300, 200, 150, Gosu::Color::RED, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(385, 380, 50, 70, Gosu::Color::BLUE, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(460, 335, 35, 35, Gosu::Color::BLUE, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(0, 450, 1000, 400, Gosu::Color::GREEN, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(200, 100, 100, 45, Gosu::Color::WHITE, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(100 , 350, 45, 120, 0xff_AC5B13 , ZOrder::TOP, mode=:default)
    Gosu.draw_triangle(20, 30, Gosu::Color::BLUE, 440, 230,  Gosu::Color::BLUE, 50, 345,  Gosu::Color::BLUE, ZOrder::TOP, mode=:default)
4

2 回答 2

0

要将蓝色三角形放置在房屋顶部,您需要使三角形的两个顶点的 Y 坐标与矩形顶部相同。

需要的矩形顶点:ToplLeft, TopRight

三角形顶点:

X1 = ToplLeft.X - OverhangSize
Y1 = ToplLeft.Y
X2 = ToplRight.X + OverhangSize
Y2 = ToplLeft.Y
X3 = (ToplLeft.X + ToplRight.X) / 2    //average vor symmetric roof
Y3 = ToplLeft.Y - RoofHeight
于 2019-09-02T08:41:04.550 回答
0

Juts 将数字更改为此。X1 = 405 y1 = 204 x2 = 290 y2 =300 x3 = 530 y3 = 300 图片

Gosu.draw_triangle(405, 204, Gosu::Color::BLUE, 290, 300, Gosu::Color::BLUE, 530, 300, Gosu::Color::BLUE, ZOrder::TOP, mode=:default)

于 2019-09-02T07:28:52.917 回答