mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 21:23:41 +00:00
Fixed a memory leak
This commit is contained in:
parent
cf02eef8fd
commit
807ff4b0d0
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <SDL_render.h>
|
#include <SDL_render.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "AnimationHandler.h"
|
#include "AnimationHandler.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
@ -14,7 +15,7 @@ class SpriteComponent : public Component
|
|||||||
public:
|
public:
|
||||||
int animationIndex = 0;
|
int animationIndex = 0;
|
||||||
|
|
||||||
std::map<AnimationType, Animation*> animations;
|
std::map<AnimationType, std::unique_ptr<Animation>> animations;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TransformComponent* transform;
|
TransformComponent* transform;
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
#include "SpriteComponent.h"
|
#include "SpriteComponent.h"
|
||||||
|
|
||||||
#include <SDL_timer.h>
|
#include <SDL_timer.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "AnimationHandler.h"
|
||||||
#include "Direction.h"
|
#include "Direction.h"
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
@ -16,11 +18,8 @@ SpriteComponent::SpriteComponent(const char* path, bool isAnimated)
|
|||||||
{
|
{
|
||||||
animated = isAnimated;
|
animated = isAnimated;
|
||||||
|
|
||||||
Animation* idle = new Animation((uint8_t)AnimationType::IDLE, 2, 200);
|
animations.emplace(IDLE, std::make_unique<Animation>((uint8_t)AnimationType::IDLE, 2, 200));
|
||||||
Animation* walk = new Animation((uint8_t)AnimationType::WALK, 2, 200);
|
animations.emplace(WALK, std::make_unique<Animation>((uint8_t)AnimationType::WALK, 2, 200));
|
||||||
|
|
||||||
animations.emplace(IDLE, idle);
|
|
||||||
animations.emplace(WALK, walk);
|
|
||||||
|
|
||||||
playAnimation(IDLE);
|
playAnimation(IDLE);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user