hx3d  1
2D/3D Simple Game Framework
fade_transition.cpp
1 /*
2  Fade screen transition.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #include "hx3d/graphics/fade_transition.hpp"
22 
23 #include "hx3d/graphics/sprite.hpp"
24 #include "hx3d/core/core.hpp"
25 #include "hx3d/window/game.hpp"
26 #include "hx3d/window/application.hpp"
27 
28 namespace hx3d {
29 namespace graphics {
30 
32  _color = color;
33 }
34 
36  Sprite spriteCurrent;
37  Sprite spriteNext;
38  spriteCurrent.setTexture(currentFB);
39  spriteNext.setTexture(nextFB);
40 
41  auto world_size = Core::CurrentGame()->getSize();
42  spriteCurrent.transform.position.x = world_size.x / 2;
43  spriteCurrent.transform.position.y = world_size.y / 2;
44  spriteCurrent.transform.rotation.z = glm::radians(180.f);
45 
46  spriteNext.transform.position.x = world_size.x / 2;
47  spriteNext.transform.position.y = world_size.y / 2;
48  spriteNext.transform.rotation.z = glm::radians(180.f);
49 
50  int alpha = (_currentTime / (_duration/2.f)) * 255;
51  if (_currentTime > _duration / 2) {
52  spriteNext.setTint(Color(255, 255, 255, alpha));
53  Framebuffer::clear(_color);
54  batch.begin();
55  batch.draw(spriteNext);
56  batch.end();
57  }
58 
59  else {
60  spriteCurrent.setTint(Color(255, 255, 255, 255 - alpha));
61  Framebuffer::clear(_color);
62  batch.begin();
63  batch.draw(spriteCurrent);
64  batch.end();
65  }
66 }
67 
68 void FadeTransition::onUpdate(float delta) {
69 
70 }
71 
73 }
74 
76 
77 }
78 
79 } /* graphics */
80 } /* hx3d */
FadeTransition(window::Game *game, Color color=Color::Black)
Create a fading transition with a color.
float _currentTime
Current time in seconds.
Definition: transition.hpp:116
static window::Game * CurrentGame()
Get the game instance.
Definition: core.cpp:82
void setTint(Color tint)
Set the mesh tint.
Definition: mesh.cpp:43
Game main class: multiple screens management.
Definition: game.hpp:42
virtual void render(Batch &batch, Framebuffer &currentFB, Framebuffer &nextFB) override
Render the transition.
Four [0..255] components defined color.
Definition: color.hpp:32
glm::vec3 position
Position.
Definition: transform.hpp:80
void setTexture(const Ptr< Texture > &texture)
Set the sprite texture.
Definition: sprite.cpp:36
virtual void end() override
End the batching.
Definition: batch.cpp:49
hx3d framework namespace
Definition: audio.hpp:26
Transition between two screens.
Definition: transition.hpp:38
virtual void onStart() override
On transition start callback.
glm::vec2 getSize()
Get the current game size.
Definition: game.cpp:88
virtual void onDone() override
On transition done callback.
float _duration
Duration in seconds.
Definition: transition.hpp:114
Simple base batch implementation. Draw at each draw call.
Definition: batch.hpp:36
virtual void onUpdate(float delta) override
On transition update callback.
virtual void begin() override
Begin the batching.
Definition: batch.cpp:38
glm::vec3 rotation
Rotation.
Definition: transform.hpp:86
virtual void draw(Mesh &mesh) override
Draw the mesh.
Definition: batch.cpp:53
2D texture manipulation.
Definition: sprite.hpp:62
Transform transform
Mesh transformation.
Definition: mesh.hpp:90
Render-to-texture buffer.
Definition: framebuffer.hpp:37
static void clear(Color color)
Clear the framebuffer.