Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - drako0812

Pages: [1]
1
Sorry about taking so long to reply. Nothing is wrong with it, I was more curious than anything. I also agree that SFML is a more important use of your development time.

2
General discussions / What happened to the Thor extension library?
« on: May 14, 2017, 06:54:05 am »
I'm assuming RL got in the way, but I haven't seen a confirmation on that. Thor was a pretty useful extension even though I haven't really utilized it, yet. If I can, I will look into what it would take to update it. Also, if there is a newer alternative that is out there, it would be great to know about.

3
I think the problem is your GameObject::setTexture method. You are passing the sf::Texture by value which means that particular instance will be destroyed as soon as that method returns.  You need to pass a reference or pointer and keep that reference or pointer alive somewhere else.

So a quick example:

In GameObject.h

// Rest of Game Object Declaration
void setTexture(const sf::Texture & gameobject_texture);
// Rest of Game Object Declaration

In GameObject.cpp

// Rest of Game Object Definition
// Basically the same as before
void GameObject::setTexture(const sf::Texture & gameobject_texture) {
    sprite.setTexture(gameobject_texture);
}
// Rest of Game Object Definition

In file where you set the texture:

// Rest of Code
sf::Texture texture; // IMPORTANT: Make sure texture outlives the GameObject
// Initialize the texture somehow
GameObject::GameObject* gameobject = GameObject::getGameObject("player_gameobject");
gameobject->setTexture(texture);
// Rest of Code

-- OR --

If you have C++11 or better compatibility (At least I think this should work)

// Rest of Code
std::shared_ptr<sf::Texture> texture = std::make_shared(new Texture()); // Now you can store the pointer somewhere else
// Initialize the texture somehow
GameObject::GameObject* gameobject = GameObject::getGameObject("player_gameobject");
gameobject->setTexture(*texture);
// Rest of Code

You could also use
std::unique_ptr<sf::Texture>
which enforces stricter ownership rules.

Pages: [1]