Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / About "translate(x, y, &drawing_code)" & about fullscreen...
- - By kaBOOM Date 2011-05-22 11:14
1.About "translate(x, y, &drawing_code)" :
Do I need the opengl gem to use this? If not, what does "&drawing_code" refer to?

2.About fullscreen:
Is there a way to switch between fullscreen and window-mode mid-game, while the program is running?

As always, thank you.
Parent - - By Dahrkael Date 2011-05-22 12:12
1. no, it works with just gosu
the & refers to a block, so its used like translate(x, y) { drawing code } i think you can pass a Proc too, but not sure

2. i think theres no clean and stable way of doing that right now
Parent - By erisdiscord Date 2011-05-22 14:28
You can pass a proc anywhere there's a block, but you have to prefix it with &. These two are roughly equivalent, although I suspect the second one is not so efficient:

translate(x, y) do
    @player.draw
end


draw_proc = proc { @player.draw }
translate(x, y, &draw_proc)


The cool thing about this is that you can pass Method objects as blocks this way too.
Parent - By erisdiscord Date 2011-05-22 14:47
To clarify what Dahrkael is saying, you call translate, rotate and scale with a block , which is a common pattern in Ruby. If you don't know about blocks, you might want to Google for more information.

The "drawing code" that goes there is just standard Gosu calls, like @image.draw(x, y, z). These transformations are applied to everything that's drawn inside of the block.

For example, using translate, one might replace code like this:

@player.draw @player_x - @scroll_x, @player_y - @scroll_y
@enemy.draw  @enemy_x  - @scroll_x, @enemy_y  - @scroll_y
...


with code like this:

translate(-@scroll_x, -@scroll_y) do
  @player.draw @player_x, @player_y, 0
  @enemy.draw  @enemy_x,  @enemy_y,  0
  ...
end


Which is, in my opinion, more readable. In practice, you'd probably want to use a more object oriented approach, but I figured it would be more clear what I was talking about this way. If you've got any further questions, don't be shy.
Parent - - By lol_o2 Date 2011-05-22 18:48
To the fullscreen:
Close the current window and open new, switched. To not disturb the game, contain it in an independent variable. Also you need to make a method which will reinitialize all images into the new window.
Parent - - By jlnr (dev) Date 2011-05-23 08:30
Sadly, this is not guaranteed to work. Gosu only accepts one Window at a time and there is no way to really, really enforce garbage collection of the Window. And because of that, Window is written in a way that expects to be the only one, ever, and may crash the game on other operating systems.
Parent - By kaBOOM Date 2011-05-23 22:23
Thanks a billion everyone!!!
Up Topic Gosu / Gosu Exchange / About "translate(x, y, &drawing_code)" & about fullscreen...

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill