Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Fade-in Fade-out, How Would You Do It?
- - By ell Date 2010-06-17 20:43
I was wondering how I would go abouts creating some sort of object that could fade in and fade out to black. I am thinking of drawing a black quad but i'm not sure about freezing the current frame etc? How would you go about it? Thanks in advance, ell
Parent - - By erisdiscord Date 2010-06-17 22:50
You could stop updating your game objects and keep drawing them as they are, with a black quad over the screen that gets darker each frame. This is done more easily with some sort of game state object that will handle that sort of stuff for you.

Are you using Ruby or C++? I definitely recommend looking at Chingu if you're using Ruby; it will do this fade in and out for you automagically.
Parent - - By ell Date 2010-06-19 12:02
I'm using Ruby, and I'd rather do it all myself, not because I'm stubborn but because I need to learn more about creating games. And by game state object, do you mean one like RPG Maker's scene system? Thanks :D
Parent - By jlnr (dev) Date 2010-06-19 12:44
One common pattern in Gosu is to have several classes like Game, Menu, Title which each have update/draw/button_down/button_up methods. The window then only has one "current state" to which it forwards all of these method calls. It's a really simple, effective way to put structure in a game.

That system does not have much to do with fading by itself, but gives you more good places to put the fading code. In any case, you can just stop calling "update" on the game objects and in "draw" just draw everything, then draw a big, transparent black quad over it.

See this raw-Gosu example by benko which coincidentally implements fading too: http://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=493
Parent - By erisdiscord Date 2010-06-19 15:44
I'm not terribly familiar with RGSS (being n a Mac and all), but what Julian said is exactly what I'm talking about. It's a pretty straightforward design pattern once you get the hang of it and it makes for much cleaner code.

Chingu actually keeps an array of game states so that you can push another state onto the end of the array instead of replacing the current one for when you want to open a menu or a pause screen but then return to the map after. It also lets you do stuff like this (roughly; not guaranteed to be a working example :) ):

  def draw
    previous_game_state.draw
    fill_screen 0x80000000
    # draw menu
  end
- By ell Date 2010-06-20 19:07
Thanks guys, you'v been a great help!
Up Topic Gosu / Gosu Exchange / Fade-in Fade-out, How Would You Do It?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill