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

Pages: [1]
1
Graphics / Re: Sprite doesn't transform in an inherited class
« on: September 28, 2019, 09:24:08 am »
So i did write my own getGloabalBounds and it works good.
Thanks !

2
Graphics / Sprite doesn't transform in an inherited class
« on: September 27, 2019, 04:55:53 pm »
Hi Forum,
i faced a problem with my inherited class and sf::sprite.
I have a custom class, that inherits from sf::Drawable and sf::Transformable
Here it is:
class DrawableObject : public sf::Drawable,public sf::Transformable
{
public:
        DrawableObject();
        ~DrawableObject();
        bool loadImage(std::string);
        sf::FloatRect getFloatRect();

private:
        sf::Texture m_texture;
        sf::Sprite m_sprite;
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                states.transform *= getTransform();
                target.draw(m_sprite, states);
        }
};
 
It works quite fine...i can render and move as expected !
But now i wanted to implement collision. I read that sf::transformable has no getGlobalBounds() function so
i thought that i just use the getGlobalBounds method from my sprite(m_sprite), but every value from the position to the FloatRect is nonsense(doesnt fit the values directly obtained from my class) !

Is there a way i can apply every tranformation i made to the class also to the Sprite ?
Thanks

3
Audio / Re: sf::Sound nullptr problem with std::map
« on: September 02, 2019, 09:08:00 pm »
Big thank to you !
I should have known(because obviously a sf::SoundBuffer is quite large) that a push_back moved the content to other adress spaces !
I decided to store my buffers in an std::list and it works like a charme !
 ;)

4
Audio / sf::Sound nullptr problem with std::map
« on: September 02, 2019, 06:02:12 pm »
Hi Forum,
so this is a rather complicated problem with sf::Sound.
I face a problem when i create a std::map with an std::string as the key-value and a sf::Sound as the second argument ! I know its not recommended to save an sf::Sound to container as it always needs to point to an sf::SoundBuffer ! But in my case i wanted to go with that solution so i created an std::vector that would store my sf::SoundBuffer ! Before i go on heres the Code:
Header(minimal example):
std::map <std::string, sf::Sound> Sounds;
std::vector<sf::SoundBuffer> soundBuffer;
 
So here are both map and vector !
Now the implementation from a function that stores a loaded sf::SoundBuffer in a Vector and an sf::Sound to
a Map
Implementation:
sf::SoundBuffer buffer;
if (buffer.loadFromFile(path))
                {
                        soundBuffer.push_back(buffer);
                        //sound_.setBuffer(soundBuffer.back());  
                        //Sounds.insert(std::pair<std::string, sf::Sound>(name, sf::Sound{soundBuffer.back()}));
                        Sounds.emplace(name, sf::Sound{ soundBuffer.back() });
                        return true;
                }
 
As you can see, i tried out a lot of things

So wheres now the problem ? When i try to play multiple sounds only the last one added is functioning.The other two(in my case i added 3 sounds as an wav) get nullptr(first screenshot).
And the sf::SoundBuffer Vector is perfectly working !
I have no idea what i did wrong(i think it isnt an out of scope problem, because it should be prevented through the Vector).
I hope u can help me !
Thanks


Pages: [1]