home *** CD-ROM | disk | FTP | other *** search
- #include "Animation2D.h"
- #include "Sequences.h"
-
- Animation2D::Animation2D(Scene2D * scene, int layer, const String & name )
- : Object2D( scene, layer ),
- sequences( Sequences::load( name, scene ) ),
- finished( true ),
- alpha( 255 ),
- current_seq( 0 ),
- current_fr( 0 ),
- time( 0 )
- {}
-
- Animation2D::~Animation2D()
- {
- Sequences::unload( sequences );
- }
-
- void Animation2D::render()
- {
- sequences->render_frame( current_seq, current_fr, alpha );
- }
-
- void Animation2D::start(int seq, bool is_loop)
- {
- if( seq < 0 )
- seq = 0;
- if( seq >= sequences->get_sequence_count() )
- seq = sequences->get_sequence_count() - 1;
- current_seq = seq;
- current_fr = 0;
- time = 0;
- loop_current = is_loop;
- finished = false;
- }
-
- bool Animation2D::life_cycle(float delta_time)
- {
- time += delta_time;
- while( time > sequences->get_duration( current_seq, current_fr ) )
- {
- time -= sequences->get_duration( current_seq, current_fr );
- ++current_fr;
- if( current_fr >= sequences->get_frame_count( current_seq ) )
- {
- if( loop_current )
- {
- current_fr = 0;
- }
- else
- {
- // ╬±≥αφεΓΦ≥ⁿ± φα ∩ε±δσΣφσ∞ ΩαΣ≡σ
- --current_fr;
- time = 0;
- finished = true;
- }
- }
- }
- return true;
- }
-
- bool Animation2D::is_finished()const
- {
- return finished;
- }
-
- void Animation2D::set_transparency(int alpha)
- {
- if( alpha < 0 ) alpha = 0;
- if( alpha > 255 ) alpha = 255;
- this->alpha = alpha;
- }
-
- void Animation2D::render_frame(int seq, int fr, int alpha)const
- {
- sequences->render_frame( seq, fr, alpha );
- }
-
- int Animation2D::get_frame_count(int seq)const
- {
- return sequences->get_frame_count( seq );
- }
- int Animation2D::get_sequence_count()const
- {
- return sequences->get_sequence_count();
- }
- int Animation2D::get_height()const
- {
- return sequences->get_height( current_seq, current_fr );
- }
- int Animation2D::get_width()const
- {
- return sequences->get_width( current_seq, current_fr );
- }
- int Animation2D::get_height(int seq, int fr)const
- {
- return sequences->get_height( seq, fr );
- }
- int Animation2D::get_width(int seq, int fr )const
- {
- return sequences->get_width( seq, fr );
- }
-