Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / bg_utils - a small extending library around Gosu
- - By bestguigui Date 2018-06-15 06:35 Edited 2018-06-15 06:53
Hi all,

https://rubygems.org/gems/bg_utils

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 :
- get_pixel
- set_pixel

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.
Parent - - By RunnerPack Date 2018-06-16 15:35 Edited 2018-06-16 15:43
This is really cool! Downloading immediately :D
Question: Can you pass a TiledImage to TiledImage#new?

EDIT: Now that I think about it, it probably wouldn't be very useful to do that... You could just increase the number of tiles in the original TiledImage.
Parent - By bestguigui Date 2018-06-16 16:24
As discussed on Discord, I'll wait until jlnr updates Gosu with Gosu::record. That way, we'll get a true Gosu::Image out of TiledImage, and we'll be able to draw it with colors and mode in a really more efficient way !
Up Topic Gosu / Extending Gosu / bg_utils - a small extending library around Gosu

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill