使用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.orgrdocGosuImage.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)