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 - neobonde

Pages: [1]
1
General / Re: SFML book, chapter 2 white box issue
« on: July 16, 2017, 01:19:22 pm »
Oh i see now, it was just a missed & on my part, thanks.
There is no misprint in the book, i just didn't notice my mistake

2
General / Re: SFML book, chapter 2 white box issue
« on: July 16, 2017, 01:08:07 pm »
Thank you it helped :), but i dont know why the version from the book does not work? :) i have even just tried out their source code and it seams to be the same problem.

And no it does not output an exception error, and yes handling it would be ideal :)

3
General / Re: SFML book, chapter 2 white box issue
« on: July 16, 2017, 11:53:02 am »
I guess that would work, but then i dont use the ResourceHolder? or am i missing something?

4
General / SFML book, chapter 2 white box issue
« on: July 15, 2017, 11:54:01 pm »
Hey everyone

I have a problem trying to get the code from chapter 2 in the sfml game development book to work.
The problem is the whitebox issue, I understand what causes the whitebox (a loss of the texture) but i simply cant figure out why im losing my texture?

Here is my ResourceHolder
#pragma once
#include <map>
#include <memory>
#include <cassert>


template<typename Resource, typename Identifier>
class ResourceHolder
{
public:
        void load(Identifier id, const std::string& filename)
        {
                std::unique_ptr<Resource> resource(new Resource());
                if (!resource->loadFromFile(filename))
                        throw std::runtime_error("ResourceHolder::load - failed to load " + filename);
                auto inserted = mResourceMap.insert(std::make_pair(id, std::move(resource)));
                assert(inserted.second);
        }

        Resource get(Identifier id)
        {
                auto found = mResourceMap.find(id);
                assert(found != mResourceMap.end());

                return *found->second;
        }

        const Resource& get(Identifier id) const
        {
                auto found = mResourceMap.find(id);
                assert(found != mResourceMap.end());

                return *found->second;
        }

private:
        std::map<Identifier, std::unique_ptr<Resource>> mResourceMap;
};

 

And this is a snippet from Game.cpp, where i use the Resource holder:

Game::Game() : mTextures() ,mPlayer() ,mWindow(sf::VideoMode(640, 480), "SFML Application")
{
       
        try
        {
                mTextures.load(Textures::Airplane, "Eagle.png");
        }
        catch (std::runtime_error& e)
        {
                std::cout << "Exception: " << e.what() << std::endl;
        }

        mPlayer.setTexture(mTextures.get(Textures::Airplane));
        mPlayer.setPosition(200.f, 200.f);
}

for reference here is Game.hpp

#include <SFML/Graphics.hpp>
#include "ResourceHolder.hpp"

namespace Textures
{
        enum ID
        {
                Landscape,
                Airplane,
                Missile
        };
}

class Game
{
public:
        Game();
        void run();

private:
        void processEvents();
        void update(sf::Time deltaTime);
        void render();

        void handlePlayerInput(sf::Keyboard::Key key, bool isPressed);

public:
        sf::Time TimePerFrame = sf::seconds(1.f / 60.f);

private:
        ResourceHolder<sf::Texture, Textures::ID> mTextures;
        sf::Texture mTexture;
        sf::Sprite mPlayer;

        sf::RenderWindow mWindow;

        bool mIsMovingUp = false;
        bool mIsMovingDown = false;
        bool mIsMovingLeft = false;
        bool mIsMovingRight = false;

};
 

Hope one of you guys can help me out, because im really stuck :)

Pages: [1]
anything