diff --git a/Bin/VC10/VC10.vcxproj b/Bin/VC10/VC10.vcxproj
index a236387..d949fcd 100644
--- a/Bin/VC10/VC10.vcxproj
+++ b/Bin/VC10/VC10.vcxproj
@@ -98,6 +98,7 @@
+
diff --git a/Bin/VC10/VC10.vcxproj.filters b/Bin/VC10/VC10.vcxproj.filters
index 639e230..c397de8 100644
--- a/Bin/VC10/VC10.vcxproj.filters
+++ b/Bin/VC10/VC10.vcxproj.filters
@@ -126,6 +126,9 @@
TMXParser
+
+ System
+
diff --git a/src/Actor/Player.cpp b/src/Actor/Player.cpp
index 5b95168..b0918d3 100644
--- a/src/Actor/Player.cpp
+++ b/src/Actor/Player.cpp
@@ -6,17 +6,12 @@ Player::Player(void) {
}
Player::~Player(void) {
- delete _player->GetTexture();
delete _player;
}
void Player::Prepare(void) {
_player = new Sprite();
- _playerTexture = new Texture();
- _playerTexture->Load("../Data/Img/Player.png");
- _player->SetTexture(_playerTexture);
- _player->SetPosition(Vec2(800/2, 600/2));
- _player->SetScale(Vec2(4.5f, 4.5f));
+ _player->LoadSprite("../Data/Img/Player.png");
}
void Player::Render(void) {
diff --git a/src/Actor/Player.h b/src/Actor/Player.h
index 382f0aa..5ee44a2 100644
--- a/src/Actor/Player.h
+++ b/src/Actor/Player.h
@@ -1,4 +1,4 @@
-#include "../Texture/Texture.h"
+#pragma once
#include "../Sprite/Sprite.h"
#include "../Global/Globals.h"
#include "../System/Debug.h"
@@ -19,6 +19,5 @@ public:
private:
float PLAYER_SPEED;
Sprite* _player;
- Texture* _playerTexture;
float _rotationAngle;
};
diff --git a/src/Sprite/Sprite.cpp b/src/Sprite/Sprite.cpp
index f0e4f88..35a711a 100644
--- a/src/Sprite/Sprite.cpp
+++ b/src/Sprite/Sprite.cpp
@@ -10,6 +10,10 @@ Sprite::Sprite() {
}
Sprite::~Sprite() {
+ if(texture) {
+ textureManager.Destroy(texture);
+ texture = NULL;
+ }
}
void Sprite::Update(float dt) {
@@ -20,10 +24,10 @@ void Sprite::Draw() const {
}
void Sprite::DrawRegion(const Rect& src) const {
- const float uvX = src.x / (float)texture->GetWidth();
- const float uvY = src.y / (float)texture->GetHeight();
- const float uvW = src.w / (float)texture->GetWidth();
- const float uvH = src.h / (float)texture->GetHeight();
+ const float uvX = src.x / (float)texture->GetWidth();
+ const float uvY = src.y / (float)texture->GetHeight();
+ const float uvW = src.w / (float)texture->GetWidth();
+ const float uvH = src.h / (float)texture->GetHeight();
// Awesome artwork to describe this:
// 0---------1
@@ -74,6 +78,20 @@ void Sprite::DrawRegion(const Rect& src) const {
glPopMatrix();
}
+bool Sprite::LoadSprite(const std::string& filename) {
+ Texture* newTexture = textureManager.Load(filename);
+ if(newTexture) {
+ if(texture) {
+ textureManager.Destroy(texture);
+ }
+ size.x = (float)newTexture->GetWidth();
+ size.y = (float)newTexture->GetHeight();
+ texture = newTexture;
+ return true;
+ }
+ return false;
+}
+
void Sprite::SetTexture(Texture* texture) {
this->texture = texture;
this->size = Vec2((float)texture->GetWidth(), (float)texture->GetHeight());
diff --git a/src/Sprite/Sprite.h b/src/Sprite/Sprite.h
index 6e87cd3..174a947 100644
--- a/src/Sprite/Sprite.h
+++ b/src/Sprite/Sprite.h
@@ -14,10 +14,14 @@ public:
virtual void Draw() const;
virtual void DrawRegion(const Rect& src) const;
+ virtual bool LoadSprite(const std::string& filename);
+
const Vec2& GetPosition() const { return position; }
float GetX(void) { return position.x; }
float GetY(void) { return position.y; }
const Vec2& GetSize() const { return size; }
+ float GetWidth() const { return size.x; }
+ float GetHeight() const { return size.y; }
const Vec2& GetScale() const { return scale; }
float GetRotation() const { return rotation; }
Texture* GetTexture() { return texture; }
diff --git a/src/System/ResourceManager.h b/src/System/ResourceManager.h
new file mode 100644
index 0000000..decf664
--- /dev/null
+++ b/src/System/ResourceManager.h
@@ -0,0 +1,96 @@
+#pragma once
+
+#include
+#include