First Code Lines


One of the ideas for Green Memories is to have a day/night cycle that will happen during gameplay, for that we'll need smooth transitions. The simplest and most effective way to do this is through fade-in/fade-out logic. Luckily, Butano already has an abstraction for color blending, so we can use that for our fade-out.

With some creativity I wrote a utility function that I hope will help us for the rest of the project:

    void fade_out(bool &fading_out, bn::bg_palette_ptr background, void (*callback)())
    {
        if (background.fade_intensity() >= 1)
        {
            fading_out = false;
            callback();
        }
        if (background.fade_intensity() <= 0)
        {
            background.set_fade(bn::colors::black, 0);
            background.set_fade_intensity(0);
        }
        background.set_fade_intensity(bn::min(background.fade_intensity() + 0.01, bn::fixed(1)));
    }

The fading_out parameter is nothing more than the address of the boolean that tells us if our fade out should be executed, and that last weird parameter is nothing more than the address of a function that I want to be executed when the fade out is finished. So basically I can pass functions as parameters.

After creating the fade in function using the same logic, we are able to make a splash screen with our logo:

    void end_scene()
    {
        scene_ended = true;
    }
    void call_fade_out()
    {
        fading_out = true;
    }   
    void logo_scene()
    {
        bn::regular_bg_ptr logo_bg = bn::regular_bg_items::logo.create_bg(0, 0);
        bn::bg_palette_ptr logo_bg_palette = logo_bg.palette();
        logo_bg_palette.set_fade(bn::colors::black, 1);
        scene_ended = false;
        fading_in = true;
        while (!scene_ended)
        {
            if(fading_out)
            {
                fade_out(fading_out, logo_bg_palette, &end_scene);
            }
            if(fading_in)
            {
                fade_in(fading_in, logo_bg_palette, &call_fade_out);
            }
            bn::core::update();
        }
    }

This brings us this result:

Get Green Memories

Leave a comment

Log in with itch.io to leave a comment.