-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleFadeToBlack.cpp
More file actions
71 lines (61 loc) · 1.56 KB
/
ModuleFadeToBlack.cpp
File metadata and controls
71 lines (61 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <math.h>
#include "Globals.h"
#include "Application.h"
#include "ModuleFadeToBlack.h"
ModuleFadeToBlack::ModuleFadeToBlack(Application* app, bool start_enabled) :
Module(app, start_enabled),
start_time(0),
total_time(0),
fading_in(true),
mod_on(NULL),
mod_off(NULL)
{
screen = {0, 0, SCREEN_WIDTH * SCREEN_SIZE, SCREEN_HEIGHT * SCREEN_SIZE};
}
ModuleFadeToBlack::~ModuleFadeToBlack()
{}
// Load assets
bool ModuleFadeToBlack::Start()
{
LOG("Preparing Fade Screen");
SDL_SetRenderDrawBlendMode(App->renderer->renderer, SDL_BLENDMODE_BLEND);
return true;
}
// Update: draw background
update_status ModuleFadeToBlack::Update()
{
if(start_time > 0)
{
Uint32 now = SDL_GetTicks() - start_time;
float normalized = (float) now / (float) total_time;
if(normalized > 1.0f)
normalized = 1.0f;
if(fading_in == false)
normalized = 1.0f - normalized;
SDL_SetRenderDrawColor(App->renderer->renderer, 0, 0, 0, (Uint8) (normalized * 255.0f));
SDL_RenderFillRect(App->renderer->renderer, &screen);
if(now >= total_time)
{
if(fading_in == true)
{
total_time += total_time;
fading_in = false;
mod_off->Disable();
mod_on->Enable();
start_time = SDL_GetTicks();
}
else
start_time = 0;
}
}
return UPDATE_CONTINUE;
}
// Fade to black. At mid point deactivate one module, then activate the other
void ModuleFadeToBlack::FadeToBlack(Module* module_off, Module* module_on, float time)
{
fading_in = true;
start_time = SDL_GetTicks();
total_time = (Uint32)(time * 0.5f * 1000.0f);
mod_on = module_on;
mod_off = module_off;
}