Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Tutorial] Fades

Hi :3
I'll explain how to make "fades" in an easy way, ill use a 640x480 resolution.

first you need a scene system like this:
viewtopic.php?f=191&t=67246

then we will make a scene called Transition with this content:

Ruby:
include Gosu

class Transition

    attr_reader :screen_x

    attr_reader :screen_y

 

    def initialize(scene, type)

        @next_scene = scene

        @time = 0

        @fading = type

        @fade_time = 255 if @fading == :in

        @fade_time = 0 if @fading == :out

        @color = Color.new(@fade_time, 0, 0 ,0)

    end

    

    def button_down(id)

    end

    

    def update

        @color = Color.new(@fade_time, 0, 0 ,0)

        case @fading

            

        when :in

            if @fade_time <= 0

                $scene = @next_scene

            else

                @fade_time -= 15 # 15 is cool

            end

        when :out

            if @fade_time >= 255

                $scene = @next_scene

            else

                @fade_time += 15 # 15 is cool

            end

        end

            

        self.draw

    end

    

    def draw

        @next_scene.update

        $window.draw_quad(0, 0, @color, 640, 0, @color, 0, 480, @color, 640, 480, @color, 500)   

    end

    

end

 

If you see the code you will know that the fade is really a black image which is increasing (or decreasing) its opacity.
Fades are normally short, because while the fade is processing, the update is running and can origin problems =)

The correct use is: $scene = Transition.new(next_scene, type_of_fade)
$scene = Transition.new(Porn_Room.new, :in/:eek:ut)
 
Something sortof related but not related, am I right in thinking we don't have to dispose things in Gosu?

draw_quad for example, it draws the quad but then will disappear on the next frame unless it's drawn again, right?
 
Gosu images are not like RGSS Sprites.

If you know, RGSS have two types of images, bitmaps and sprites.

Bitmaps need a rect to be showed. Gosu makes Bitmaps with its own rect to be showed, so dont need to dispose nothing =)
 

e

Sponsor

But yes, from experience, if you don't draw it on every tick it WILL disappear. Or maybe I'm doing it wrong? If I don't redraw images, they disappear; now I haven't tried using the Window's draw_quad or draw_line method; do these stay until painted over?
 
Gosu includes at the beginning of all frames something like

"self.contents.clear" so you need to redraw all the things you want in the screen.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top