diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | library.cpp | 3 | ||||
-rw-r--r-- | library.h | 1 | ||||
-rw-r--r-- | object_base.cpp | 10 | ||||
-rw-r--r-- | sprite.cpp | 5 | ||||
-rw-r--r-- | sprite.h | 5 |
6 files changed, 14 insertions, 12 deletions
@@ -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; @@ -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); } @@ -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); +} @@ -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); }; |