Mana
Loading...
Searching...
No Matches
animation.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "resources/imageset.h"
25#include "utils/xml.h"
26
27#include <vector>
28
29class Image;
30
34struct Frame
35{
37 int delay;
40};
41
46class Animation final
47{
48 public:
49 Animation() = default;
50
54 void addFrame(Image *image, int delay, int offsetX, int offsetY);
55
60 void addTerminator();
61
65 Frame *getFrame(int index) { return &(mFrames[index]); }
66
70 int getLength() const { return mFrames.size(); }
71
75 int getDuration() const { return mDuration; }
76
80 static bool isTerminator(const Frame &phase);
81
85 static Animation fromXML(XML::Node node,
86 const std::string &dyePalettes = {});
87
88 protected:
90 std::vector<Frame> mFrames;
91 int mDuration = 0;
92};
An animation consists of several frames, each with their own delay and offset.
Definition animation.h:47
Frame * getFrame(int index)
Returns the frame at the specified index.
Definition animation.h:65
static bool isTerminator(const Frame &phase)
Determines whether the given animation frame is a terminator.
Definition animation.cpp:45
int getLength() const
Returns the length of this animation in frames.
Definition animation.h:70
Animation()=default
void addFrame(Image *image, int delay, int offsetX, int offsetY)
Appends a new animation at the end of the sequence.
Definition animation.cpp:29
int mDuration
Definition animation.h:91
std::vector< Frame > mFrames
Definition animation.h:90
int getDuration() const
Returns the duration of this animation in milliseconds.
Definition animation.h:75
ResourceRef< ImageSet > mImageSet
Definition animation.h:89
static Animation fromXML(XML::Node node, const std::string &dyePalettes={})
Loads an animation from XML.
Definition animation.cpp:50
void addTerminator()
Appends an animation terminator that states that the animation should not loop.
Definition animation.cpp:40
Defines a class for loading and storing images.
Definition image.h:45
Automatically counting Resource reference.
Definition resource.h:74
A single frame in an animation, with a delay and an offset.
Definition animation.h:35
Image * image
Definition animation.h:36
int delay
Definition animation.h:37
int offsetX
Definition animation.h:38
int offsetY
Definition animation.h:39