SpriteRenderer

This commit is contained in:
Isuru Samarathunga
2025-10-11 20:18:11 +05:30
parent 7191fb19f0
commit e0411333fb
7 changed files with 289 additions and 15 deletions

View File

@ -16,12 +16,12 @@
#pragma once
#include <IACore/Map.hpp>
#include <IACore/Exception.hpp>
#include <IACore/Logger.hpp>
#include <IACore/Map.hpp>
#include <IACore/Memory.hpp>
#include <IACore/String.hpp>
#include <IACore/Vector.hpp>
#include <IACore/Exception.hpp>
#include <IAEngine/glm/ext/matrix_clip_space.hpp>
#include <IAEngine/glm/ext/matrix_transform.hpp>
@ -111,7 +111,22 @@ namespace ia::iae
Vec4 GetAsFloatVec() CONST
{
return {(FLOAT32)R/255.0f, (FLOAT32)G/255.0f, (FLOAT32)B/255.0f, (FLOAT32)A/255.0f};
return {(FLOAT32) R / 255.0f, (FLOAT32) G / 255.0f, (FLOAT32) B / 255.0f, (FLOAT32) A / 255.0f};
}
Color operator+(IN CONST Color &other) CONST
{
return Color{(UINT8) (R + other.R), (UINT8) (G + other.G), (UINT8) (B + other.B), (UINT8) (A + other.A)};
}
Color operator-(IN CONST Color &other) CONST
{
return Color{(UINT8) (R - other.R), (UINT8) (G - other.G), (UINT8) (B - other.B), (UINT8) (A - other.A)};
}
Color operator*(IN FLOAT32 v) CONST
{
return Color{(UINT8) (R * v), (UINT8) (G * v), (UINT8) (B * v), (UINT8) (A * v)};
}
};

View File

@ -0,0 +1,88 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IAEngine/Components/TextureComponent.hpp>
namespace ia::iae
{
class SpriteComponent : public TextureComponent
{
public:
struct AnimationKeyFrame
{
Handle Texture;
INT32 Duration{100};
BOOL ShouldInterpolate{};
FLOAT32 Rotation{};
Vec2 Position{};
Vec2 Scale{1.0f, 1.0f};
Color ColorOverlay{0xFF, 0xFF, 0xFF, 0xFF};
};
struct Animation
{
BOOL ShouldLoop{false};
Vector<AnimationKeyFrame> Keys;
};
public:
SpriteComponent(IN Node2D *node);
public:
VIRTUAL VOID Draw();
VIRTUAL VOID DebugDraw();
VIRTUAL VOID Update();
VIRTUAL VOID FixedUpdate();
public:
Handle AddAnimation(IN CONST Animation &animation);
VOID SetActiveAnimation(IN Handle animation);
VOID ForceSetActiveAnimation(IN Handle animation);
VOID SetAnimationFrame(IN INT32 animation, IN INT32 frame);
public:
Vector<Animation> &Animations()
{
return m_animations;
}
CONST Vector<Animation> &Animations() CONST
{
return m_animations;
}
private:
VOID UpdateAnimation();
AnimationKeyFrame GetKeyFrame(IN INT32 index);
private:
FLOAT32 m_timelinePosition{};
Animation m_activeAnimation{};
Handle m_activeAnimationHandle{INVALID_HANDLE};
Vector<Animation> m_animations;
AnimationKeyFrame m_currentAnimationState{};
AnimationKeyFrame m_nextAnimationKeyFrame{};
AnimationKeyFrame m_prevAnimationKeyFrame{};
INT32 m_prevAnimationKeyFrameIndex{};
};
} // namespace ia::iae

View File

@ -23,17 +23,17 @@ namespace ia::iae
class TextureComponent : public IComponent
{
public:
TextureComponent(IN Node2D *node);
TextureComponent(IN Node2D *node);
public:
VOID Draw();
VOID DebugDraw();
VOID Update();
VOID FixedUpdate();
VIRTUAL VOID Draw();
VIRTUAL VOID DebugDraw();
VIRTUAL VOID Update();
VIRTUAL VOID FixedUpdate();
public:
VOID SetTexture(IN Handle image);
VOID SetTexture(IN Handle image);
Handle GetTexture() CONST
{
@ -97,6 +97,6 @@ namespace ia::iae
Vec2 m_drawnSize{};
Vec2 m_textureExtent{};
Handle m_texture{INVALID_HANDLE};
Handle m_texture{0};
};
} // namespace ia::iae

View File

@ -16,10 +16,23 @@
#pragma once
#include <IAEngine/Nodes/Node2D.hpp>
#include <IAEngine/Components/SpriteComponent.hpp>
#include <IAEngine/Nodes/Node2D.hpp>
namespace ia::iae
{
}
class SpriteNode : public Node2D
{
public:
SpriteNode(IN CONST String &name);
public:
SpriteComponent *GetSpriteComponent()
{
return m_spriteComponent;
}
protected:
SpriteComponent *CONST m_spriteComponent{};
};
} // namespace ia::iae