hx3d  1
2D/3D Simple Game Framework
transition.cpp
1 /*
2  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/transition.hpp"
22 
23 namespace hx3d {
24 namespace graphics {
25 
27  _duration = 1.f;
28  _currentTime = 0.f;
29  _running = false;
30 
31  _game = game;
32 }
33 
35  _currentTime = 0.f;
36  _running = true;
37 
38  onStart();
39 }
40 
42  _currentTime = 0.f;
43  _running = false;
44 }
45 
46 void Transition::setDuration(float duration) {
47  _duration = duration;
48 }
49 
50 bool Transition::isFinished() const {
51  return _running && _currentTime >= _duration;
52 }
53 
54 bool Transition::isRunning() const {
55  return _running;
56 }
57 
58 void Transition::update(float delta) {
59  if (_running) {
60  _currentTime += delta;
61  onUpdate(delta);
62  }
63 }
64 
67 void Transition::onUpdate(float delta) {}
68 
69 } /* graphics */
70 } /* hx3d */
float _currentTime
Current time in seconds.
Definition: transition.hpp:116
bool _running
Is the transition running.
Definition: transition.hpp:118
void reset()
Reset the transition.
Definition: transition.cpp:41
virtual void onUpdate(float delta)
On transition update callback.
Definition: transition.cpp:67
Game main class: multiple screens management.
Definition: game.hpp:42
void start()
Start the transition.
Definition: transition.cpp:34
hx3d framework namespace
Definition: audio.hpp:26
float _duration
Duration in seconds.
Definition: transition.hpp:114
bool isRunning() const
Is the transition running.
Definition: transition.cpp:54
virtual void onDone()
On transition done callback.
Definition: transition.cpp:65
virtual void onStart()
On transition start callback.
Definition: transition.cpp:66
void setDuration(float duration)
Set the transition duration.
Definition: transition.cpp:46
bool isFinished() const
Is the transition finished.
Definition: transition.cpp:50
void update(float delta)
Update the transition.
Definition: transition.cpp:58
Transition(window::Game *game)
Create a transition.
Definition: transition.cpp:26
window::Game * _game
Current game.
Definition: transition.hpp:120