Mana
Loading...
Searching...
No Matches
simpleanimation.cpp
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#include "simpleanimation.h"
23
24#include "graphics.h"
25
26#include "resources/animation.h"
27#include "resources/image.h"
28#include "resources/imageset.h"
30
32 : mAnimation(std::move(animation))
33 , mInitialized(true)
34{
35 if (mAnimation.getLength() > 0)
37}
38
40 const std::string &dyePalettes)
41{
42 if (animationNode)
43 {
44 mAnimation = Animation::fromXML(animationNode, dyePalettes);
45 mInitialized = true;
46 }
47
48 if (mAnimation.getLength() > 0)
50}
51
52bool SimpleAnimation::draw(Graphics *graphics, int posX, int posY) const
53{
55 return false;
56
58 posX + mCurrentFrame->offsetX,
59 posY + mCurrentFrame->offsetY);
60}
61
67
69{
70 if (frame < 0)
71 frame = 0;
72 if (frame >= mAnimation.getLength())
73 frame = mAnimation.getLength() - 1;
74 mAnimationPhase = frame;
76}
77
96
98{
99 if (mCurrentFrame)
100 return mCurrentFrame->image;
101 return nullptr;
102}
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
int getLength() const
Returns the length of this animation in frames.
Definition animation.h:70
static Animation fromXML(XML::Node node, const std::string &dyePalettes={})
Loads an animation from XML.
Definition animation.cpp:50
A central point of control for graphics.
Definition graphics.h:78
bool drawImage(const Image *image, int x, int y)
Blits an image onto the screen.
Definition graphics.cpp:36
Defines a class for loading and storing images.
Definition image.h:45
Frame * mCurrentFrame
Current animation phase.
int mAnimationTime
Time in milliseconds the current frame is shown.
int mAnimationPhase
Index of current animation phase.
bool mInitialized
Tell whether the animation is ready.
Image * getCurrentImage() const
void update(int dt)
bool draw(Graphics *graphics, int posX, int posY) const
SimpleAnimation(Animation animation)
Creates a simple animation with an already created animation.
void setFrame(int frame)
Animation mAnimation
The hosted animation.
void reset()
Resets the animation.
Graphics * graphics
Definition client.cpp:104
Image * image
Definition animation.h:36
int delay
Definition animation.h:37
int offsetX
Definition animation.h:38
int offsetY
Definition animation.h:39