使用 Ruby Gosu,我以这种方式绘制图像:
@background_image.draw(0, 0, 0)
图像比窗口大,有没有办法神奇地调整它的大小以适应窗口?我试图避免硬编码factor_x
和factor_y
.
您可以使用类似这样的方法计算 factor_x\factor_y(假设您的窗口存储在 @window 中)
fx = @window.width/@background_image.width
fy = @window.height/@background_image.height
@background_image.draw(0, 0, 0, fx, fy)
或者使用 draw_as_quad 方法,但它稍微有点冗长(http://www.libgosu.org/rdoc/Gosu/Image.html#draw_as_quad-instance_method)
@background_image.draw_as_quad(0, 0, 0xffffffff, @window.width, 0, 0xffffffff, @window.width, @window.height, 0xffffffff, 0, @window.height, 0xffffffff, 0)