diff --git a/sdlpp/sdlpp_renderobject.cpp b/sdlpp/sdlpp_renderobject.cpp index 1a7cbc8..8ea8045 100644 --- a/sdlpp/sdlpp_renderobject.cpp +++ b/sdlpp/sdlpp_renderobject.cpp @@ -104,10 +104,10 @@ std::shared_ptr< Renderer > RenderObject::getRenderer() const { void RenderObject::setSceneID( int id ) { scene_id = id; } -void RenderObject::copyTo(std::shared_ptr other) { +void RenderObject::copyTo( std::shared_ptr< RenderObject > other ) { other->collisions.clear(); for ( auto &colider : collisions ) { - other->collisions.push_back(colider->copySelf()); + other->collisions.push_back( colider->copySelf() ); } other->texture.reset(); if ( texture ) { @@ -119,4 +119,7 @@ void RenderObject::copyTo(std::shared_ptr other) { } other->colidedWith.clear(); } +void RenderObject::saveCurTexture() { + cur_texture = texture; +} } // namespace SDLPP diff --git a/sdlpp/sdlpp_renderobject.hpp b/sdlpp/sdlpp_renderobject.hpp index 6131827..e55a43e 100644 --- a/sdlpp/sdlpp_renderobject.hpp +++ b/sdlpp/sdlpp_renderobject.hpp @@ -78,11 +78,13 @@ public: bool isStatic(); void setStatic( bool stat = true ); std::shared_ptr< Renderer > getRenderer() const; + void saveCurTexture(); protected: - virtual void copyTo(std::shared_ptr other); + virtual void copyTo( std::shared_ptr< RenderObject > other ); std::vector< std::shared_ptr< CollisionPolygon > > collisions; std::shared_ptr< Texture > texture; + std::shared_ptr< Texture > cur_texture; std::shared_ptr< Renderer > renderer; std::shared_ptr< CollisionPolygon > polygon; double movementSpeed = 0; diff --git a/sdlpp/sdlpp_scene.cpp b/sdlpp/sdlpp_scene.cpp index bf17db5..1b6c8ea 100644 --- a/sdlpp/sdlpp_scene.cpp +++ b/sdlpp/sdlpp_scene.cpp @@ -121,6 +121,7 @@ void Scene::renderScene( bool clear_renderer ) { SDL_RenderCopy( renderer->getRendererPtr(), background->getTexturePtr(), NULL, NULL ); for ( const auto &x : render_objects ) { + x->saveCurTexture(); x->render(); } } diff --git a/sdlpp/sdlpp_texture.cpp b/sdlpp/sdlpp_texture.cpp index 09f80f6..70c6e89 100644 --- a/sdlpp/sdlpp_texture.cpp +++ b/sdlpp/sdlpp_texture.cpp @@ -55,7 +55,8 @@ Texture::Texture( std::shared_ptr< Renderer > &renderer, Font &font, setTextureFromSurface( renderer, surface ); } Texture::~Texture() { - SDL_DestroyTexture( texture ); + if ( texture != nullptr ) + SDL_DestroyTexture( texture ); } SDL_Texture *Texture::getTexturePtr() { return texture;