summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-12-31 09:23:28 +0100
committertomsmeding <tom.smeding@gmail.com>2016-12-31 09:23:28 +0100
commit8023d607f128ef4b4e63b833fc2045f7b41a1e3f (patch)
tree6c44c2628c5f36a1564c9010d25ae37ed1b4e3ce
parent0cc504d3aa972cc8d5d501d9278e8773a810985a (diff)
SFML sprites!
-rw-r--r--TODO2
-rw-r--r--library.cpp3
-rw-r--r--library.h1
-rw-r--r--object_base.cpp10
-rw-r--r--sprite.cpp5
-rw-r--r--sprite.h5
6 files changed, 14 insertions, 12 deletions
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..cb8c0ff
--- /dev/null
+++ b/TODO
@@ -0,0 +1,2 @@
+- Group textures together:
+ http://www.sfml-dev.org/tutorials/2.4/graphics-sprite.php#the-importance-of-using-as-few-textures-as-possible
diff --git a/library.cpp b/library.cpp
index 12a9077..38bbf48 100644
--- a/library.cpp
+++ b/library.cpp
@@ -9,9 +9,6 @@
using namespace std;
-extern sf::RenderWindow window;
-
-
static const Font *currentFont=nullptr;
static sf::Text sharedSfText;
diff --git a/library.h b/library.h
index af2eedc..e3e87c3 100644
--- a/library.h
+++ b/library.h
@@ -9,6 +9,7 @@ using namespace std;
extern Global global;
+extern sf::RenderWindow window;
template <typename ObjT>
diff --git a/object_base.cpp b/object_base.cpp
index ce97f2a..d04d0f5 100644
--- a/object_base.cpp
+++ b/object_base.cpp
@@ -1,5 +1,6 @@
#include <iostream>
#include <cassert>
+#include <SFML/Graphics.hpp>
#include "object_base.h"
#include "library.h"
@@ -21,12 +22,9 @@ void Object::destroy(void){}
void Object::step(void){}
void Object::draw(void){
- /*if(!sprite_index){
+ if(!sprite_index){
return;
}
- if(!sprite_index->fl_image){
- sprite_index->fl_image=new Fl_PNG_Image(nullptr,sprite_index->image,sprite_index->image_len);
- assert(!sprite_index->fl_image->fail());
- }
- sprite_index->fl_image->draw((int)x,(int)y);*/
+ sprite_index->sf_sprite.setPosition(sf::Vector2f(x,y));
+ window.draw(sprite_index->sf_sprite);
}
diff --git a/sprite.cpp b/sprite.cpp
index e3503ea..260c54f 100644
--- a/sprite.cpp
+++ b/sprite.cpp
@@ -2,4 +2,7 @@
Sprite::Sprite(const unsigned char *image,unsigned int image_len)
- :image(image),image_len(image_len)/*,fl_image(nullptr)*/{}
+ :image(image),image_len(image_len){
+ sf_texture.loadFromMemory(image,image_len);
+ sf_sprite.setTexture(sf_texture);
+}
diff --git a/sprite.h b/sprite.h
index b52026a..b5d9e7d 100644
--- a/sprite.h
+++ b/sprite.h
@@ -1,13 +1,14 @@
#pragma once
-//#include <FL/Fl_PNG_Image.H>
+#include <SFML/Graphics.hpp>
class Sprite{
public:
const unsigned char *image;
unsigned int image_len;
- //Fl_PNG_Image *fl_image;
+ sf::Texture sf_texture;
+ sf::Sprite sf_sprite;
Sprite(const unsigned char *image,unsigned int image_len);
};