//
//  Animation.hpp
//  Meteor
//
//  Created by Cesar Parent on 27/08/2015.
//  Copyright © 2015 Cesar Parent. All rights reserved.
//

#ifndef Animation_hpp
#define Animation_hpp

#include "TimedActions.h"
#include "../Geometry.h"
#include <initializer_list>
#include <vector>

NS_BEGIN

/*!
 * @internal
 * @brief           Animation animates a SpriteNode object between multiple frames
 *                  on the same spritesheet.
 */
class Animation : public TimedAction {
public:
    /*!
     * @internal
     * @brief       Creates an animation with the given list of frame indices and the given
     *              frame interval.
     * @param       frames      List of frame numbers.
     * @param       interval    Duration for which each frame is displayed.
     */
    Animation(std::initializer_list<int> frames, double interval);
    
    /*!
     * @internal
     * @Brief       Animation destructor.
     */
    virtual ~Animation() {};

    
    /*!
     * @internal
     * @brief       Called once the target has been set, prepares the animation.
     */
    virtual void
    start() override;
    
    /*!
     * @internal
     * @brief       Method that updates the frame animation once per frame.
     */
    virtual void
    update(double delta) override;
    
private:
    
    std::vector<int> _frames;
    
    int     _currentFrame;
    double  _interval;
    size2   _spriteSheetSize;
    size2   _frameSize;
};

NS_END

#endif /* Animation_hpp */
