I created this small gem to keep somewhere at the same place all the various methods I need to create that can be used in other projects.
The current release is adding two useful methods :
to allow read / write pixel methods from / to a Gosu::Image.
But it also adds a new feature : the possibility to draw a TiledImage. It works like this :
Image used in this example :
@image = BgUtils::TiledImage.new('texture.png', 160, 160, 2, 2)
In this case, I load the 'texture.png' file inside a Gosu::Image, and ask for a quad of 160 * 80 pixels. The image is 16 * 16 pixels, and I want it to be displayed twice big, so I set repeat 2 times in width and 2 times in height. I can also set a Gosu::Image as first argument.
Applying a simple draw call, that gives the result :
@image.draw(40, 40, 0)
You can use arbitrary size for the desired rectangle, and use any float values for scale_x and scale_y, that don't have to be the same values.
You can also use draw_rot and draw_as_quad, with minor argument modifications, as we'll see in next examples. All indications to colors and drawing modes were removed, compared to the classic Gosu::Image draw methods.
For example :
@image.draw_as_quad(0, 0, 120, 5, 10, 130, 140, 160, 0)
Internally, it uses Gosu macro (Gosu::record) method, so you can't use colors and set drawing modes within draw methods. But you can do it if you set color and drawing mode inside the constructor inside.
For example, let's modify the creation of the image, setting color to red :
@image = BgUtils::TiledImage.new('texture.png', 160, 160, 2.0, 2.0, Gosu::Color::RED)
And now, let's display it using for example the draw_rot method :
@image.draw_rot(150, 150, 0, 35, 0.5, 0.5)
Feel free to ask for any useful method that could be added to this small gem. I'll keep it updated anytime I create something new.