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.


Topics - Cr0n

Pages: [1]
1
Graphics / [Solved] How to move a View
« on: June 13, 2020, 02:57:51 pm »
Sup!
I dont quite get my error here:

mWorldView.move(-100,400);
Does work perfectly fine - however:

When I first center some sprites relative to the view...

mPlayer.setPosition(mWorldView.getCenter());


They wont move if I move the View. I am confident that I only center them once.

Help appreciated
Cr0n :)

2
General / ["SOLVED"] Too dumb for OOP
« on: April 28, 2020, 09:37:08 pm »
Hello!
Soo, my skills are down to storing dynamic Font objects in a linked list and letting it shoot sprites. That is nice.
Now I wanted to store Textures in a std::map. I used a std::String as key and an unique pointer to a sf::Texture as the value.

std::map<std::string, std::unique_ptr<sf::Texture>> textures;
    textures["poop"] = loadTexture("res/kugel.png");

    sf::Sprite obj;
    std::map<std::string, std::unique_ptr<sf::Texture>>::iterator it = textures.find("poop");
    obj.setTexture(*(it->second));;

Results not in the Texture but in a big white plane.
Or, more specific, if I put view.zoom(1.01) in the update loop, you begin to see a white line.
Why a white line and not the texture???


Am I using the map wrong? Am i too dumb for object oriented programming?

Because:
I also tried (first, actually) to make my own player class which inherits from sf::Sprite.

class poop : public sf::Sprite {
    public:
        poop(std::map<std::string, std::unique_ptr<sf::Texture>> textures){ //
            score = 0;
            lives = 3;
            std::map<std::string, std::unique_ptr<sf::Texture>>::iterator it = textures.find("poop");
            setTexture(*(it->second));;
            std::cout << getTexture()->isSmooth();
        }

Funfact:
THIS DOES NOT WORK
I dont even see a white screen this time. I just see black nothingness.
Its almost as I didnt even set a texture. Still, I get '0' for the isSmooth() - that does mean I set the texture, or does it?

I pass the map via move as it is supposed to be since you cant copy UNIQUE pointers (learned it the hard way)

    poop mPlayer(std::move(textures));

I really have no clue why the first thing does not work and furthermore why the own-class-thing does not work I mean I give the adress of the beginning of the wanted value (sorted to key "poop" which is a texture) to the sprite object WHY does that not work?

And where is the difference if I am now doing it in my own class that inherits from sprite? It is indeed inherited as public so that shouldnt be the problem either?


Please I think all my question are quite dumb I have no idea what im doing so maybe if you show me how it is done right maybe I know how it is right too in the future maybe I could learn from it.
Im thanking you very much for reading this :)
~Cron


---

Edit1:

If I exclude the map and try to set the Texture via loadTexture directly, I still only get a white image, but this time it has the rectangular size of the original image and is centered nicely in the middle of the screen (where it should be)
sf::Sprite obj;
    obj.setTexture(*loadTexture("res/kugel.png"));;

std::unique_ptr<sf::Texture> loadTexture(std::string filename) {
    std::unique_ptr<sf::Texture> texture(new sf::Texture());
    if (!texture->loadFromFile(filename))
        throw std::runtime_error("ResourceHolder::load - Failed to load " + filename);
    return texture;
};

I am doing something terribly wrong aint I

Edit2

I modifed it to THIS:
    obj.setTexture(*loadTexture("res/kugel.png"));;
    sf::Image f = (obj.getTexture()->copyToImage()) ;
    std::cout << f.getPixel(1,2).toInteger();

it resulted in my PC to stop working for 2 Minutes after finally throwing a seg fault.
(i doubt you need this inform. but im runnin Ubuntu 18.04 and SFML Vers. is (idk downloaded it somwhere last month)
So Map is prob. fine, but why isnt loadTexture???


Pages: [1]