-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleTransition.cpp
More file actions
71 lines (52 loc) · 2.12 KB
/
ModuleTransition.cpp
File metadata and controls
71 lines (52 loc) · 2.12 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 "ModuleTransition.h"
#include "Game.h"
#include "ModuleRender.h"
#include "SDL/include/SDL_render.h"
ModuleTransition::ModuleTransition(bool startEnabled) : Module(startEnabled) {
screenRect = { 0, 0, SCREEN_WIDTH * SCREEN_SIZE, SCREEN_HEIGHT * SCREEN_SIZE };
}
ModuleTransition::~ModuleTransition() {}
bool ModuleTransition::Start() {
LOG("Preparing Fade Screen");
// Enable blending mode for transparency
SDL_SetRenderDrawBlendMode(game->GetModuleRender()->GetRenderer(), SDL_BLENDMODE_BLEND);
return true;
}
UPDATE_STATUS ModuleTransition::Update() {
// Exit this function if we are not performing a fade
if (currentStep == Transition_Step::NONE) { return UPDATE_STATUS::UPDATE_CONTINUE; }
if (currentStep == Transition_Step::TO_BLACK) {
++frameCount;
if (frameCount >= maxFadeFrames) {
moduleToDisable->Disable();
moduleToEnable->Enable();
currentStep = Transition_Step::FROM_BLACK;
}
}
else {
--frameCount;
if (frameCount <= 0) { currentStep = Transition_Step::NONE; }
}
return UPDATE_STATUS::UPDATE_CONTINUE;
}
UPDATE_STATUS ModuleTransition::PostUpdate() {
// Exit this function if we are not performing a fade
if (currentStep == Transition_Step::NONE) { return UPDATE_STATUS::UPDATE_CONTINUE; }
float fadeRatio = ((float)frameCount / (float)maxFadeFrames);
// Render the black square with alpha on the screen
SDL_SetRenderDrawColor(game->GetModuleRender()->GetRenderer(), 0, 0, 0, (Uint8)(fadeRatio * 255.0f));
SDL_RenderFillRect(game->GetModuleRender()->GetRenderer(), &screenRect);
return UPDATE_STATUS::UPDATE_CONTINUE;
}
bool ModuleTransition::Transition(Module* moduleToDisable, Module* moduleToEnable, float frames) {
// If we are already in a fade process, ignore this call
if (currentStep == Transition_Step::NONE) {
currentStep = Transition_Step::TO_BLACK;
frameCount = 0;
maxFadeFrames = frames;
this->moduleToDisable = moduleToDisable;
this->moduleToEnable = moduleToEnable;
return true;
}
return false;
}