FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_objAnim.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_OBJANIM_HPP_INCLUDED
18#define _FGE_C_OBJANIM_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "C_object.hpp"
22#include "FastEngine/accessor/C_animation.hpp"
23#include <chrono>
24#include <string>
25
26#define FGE_OBJANIM_DEFAULT_TICKDURATION_MS 10
27#define FGE_OBJANIM_CLASSNAME "FGE:OBJ:ANIM"
28
29namespace fge
30{
31
32class FGE_API ObjAnimation : public fge::Object
33{
34public:
36 explicit ObjAnimation(fge::Animation const& animation, fge::Vector2f const& position = fge::Vector2f());
37
38 FGE_OBJ_DEFAULT_COPYMETHOD(fge::ObjAnimation)
39
40 void setAnimation(fge::Animation const& animation);
41 void setTextureRect(fge::RectInt const& rectangle);
42
43 void setColor(fge::Color const& color);
44
45 void setPause(bool flag);
46 bool isPaused() const;
47
48 void refresh();
49
50 void setTickDuration(std::chrono::milliseconds const& tms);
51 std::chrono::microseconds const& getTickDuration() const;
52
53 fge::Animation const& getAnimation() const;
54 fge::Animation& getAnimation();
55 fge::RectInt const& getTextureRect() const;
56
57 fge::Color getColor() const;
58
59 FGE_OBJ_UPDATE_DECLARE
60 FGE_OBJ_DRAW_DECLARE
61
62 void save(nlohmann::json& jsonObject, fge::Scene* scene) override;
63 void load(nlohmann::json& jsonObject, fge::Scene* scene) override;
64 void pack(fge::net::Packet& pck) override;
65 void unpack(fge::net::Packet const& pck) override;
66
67 char const* getClassName() const override;
68 char const* getReadableClassName() const override;
69
72
73private:
74 void updatePositions();
75 void updateTexCoords();
76
78 fge::Animation g_animation;
79 fge::RectInt g_textureRect;
80
81 std::chrono::microseconds g_tickDuration;
82 std::chrono::microseconds g_nextFrameTime;
83
84 bool g_paused;
85};
86
87} // namespace fge
88
89#endif // _FGE_C_OBJANIM_HPP_INCLUDED
Class that represent/handle an animation.
Definition C_animation.hpp:36
Definition C_color.hpp:35
Definition C_objAnim.hpp:33
char const * getClassName() const override
Get the unique class name of the object.
void pack(fge::net::Packet &pck) override
Pack the object into a packet.
char const * getReadableClassName() const override
Get a readable version of the class name.
void save(nlohmann::json &jsonObject, fge::Scene *scene) override
Save the object to a json object.
void unpack(fge::net::Packet const &pck) override
Unpack the object from a packet.
fge::RectFloat getGlobalBounds() const override
Get the global bounds of the object.
fge::RectFloat getLocalBounds() const override
Get the local bounds of the object (without any transformations)
void load(nlohmann::json &jsonObject, fge::Scene *scene) override
Load the object from a json object.
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
Definition C_packet.hpp:70
Definition C_vertexBuffer.hpp:45