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

Pages: [1]
1
Graphics / Re: How to move a View
« on: June 14, 2020, 12:52:10 am »
Uh ok it was a timing issue.
Case closed sorry for spam

2
Graphics / Re: How to move a View
« on: June 13, 2020, 07:03:08 pm »
Ok now this is weird:

I have instanced another sf::View.
Thats my code structure with it:


sf::View view1;
sf::View view2;

while(window.isOpen(){
window.setView(view1);
...
...
window.clear();
window.draw(...);
window.display();
if(mode){
      window.setView(view2);
      ...

   }
}
elseif(otherMode){
   ...
   view1.move(x,y);
      window.clear();
      window.draw(....);
      window.display();
 

Makes the moving work!
But removing the window.setView(view2) part prevents it from working again.

Furthermore, I can set the bounds from view2 to whatever I like - the object from if(mode) are all at the same place - its like totally broken - im apparently not drawing to view2, but it still does something (that i didnt want but that somehow solved the other problem)

Cr0n

3
Graphics / Re: How to move a View
« on: June 13, 2020, 07:01:59 pm »
But as I said I dont let it follow the view??
I only set the player in the middle of the view once

Quote
mPlayer.setPosition(mWorldView.getCenter());


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

4
Graphics / Re: How to move a View
« on: June 13, 2020, 04:03:39 pm »
no I really mean that they stay at the same pixel position

5
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 :)

6
General / Re: Too dumb for OOP
« on: May 01, 2020, 12:45:17 am »
Hello again   ::)

as I dont want to spam the Forum and the title is universal applicable:

Exactly when does .getGlobalBounds() get updated?
I have a lot of Sprites, and they are all underneath each other. The player is scrolling over them.
I want to check if the player is in a certain colored area of the Backgroundsprite.
All those BG-Sprites are stored in a linked list, "PipeRenderTargets".

(heres the code:)


    for (auto const &n : pipeRenderTargets) {
                nC++;
                if(n.getGlobalBounds().intersects(mPlayer.getGlobalBounds())) {

                    sf::Vector2<int> nTop(n.getGlobalBounds().left, n.getGlobalBounds().top);
                    if((int)(mPlayer.getPosition().x + mPlayer.getGlobalBounds().width/2 - nTop.x)>0 && (int) (mPlayer.getPosition().y + mPlayer.getGlobalBounds().height/2 - nTop.y)>0) {
                        std::cout << (int) mPlayer.getPosition().x + mPlayer.getGlobalBounds().width/2 - nTop.x << "   " << (int)mPlayer.getPosition().y + mPlayer.getGlobalBounds().height/2 - nTop.y << "\n";
                        sf::Color result = peip.getPixel((int) mPlayer.getPosition().x + mPlayer.getGlobalBounds().width/2 - nTop.x,
                                                         (int) mPlayer.getPosition().y + mPlayer.getGlobalBounds().height/2 - nTop.y);
                        c++;
                        if(result.r == 237 && result.g == 239 && result.b == 235) {
                            std::cout << "Player track";
                            std::cout << -nTop.y;
                            delayer++;
                            if (delayer == 10) {
                                delayer = 0;
                                mPlayer.setPoopColor(*new sf::Color(255, 255, 255, 255));
                            }
                        }
                        else {
                            std::cout << "Player non track " << nC;
                            std::cout << "\n" << result.r << "  " << result.g << "  " << result.b << "\n";
                            std::cout << "  NOT " << (int)mPlayer.getPosition().y << "  " << mPlayer.getGlobalBounds().height/2 << "  " << - nTop.y << "\n";

                            c++;
                            mPlayer.setPoopColor(sf::Color::Red);
                        }
                    }
                }
            }


First, I iterate through the list and check if the bounds of the Backgroundtile and the Player intersect:
If they do, I store the origin of the tile. Then, I do a sanity check if the position of the player - the tile origin position is positive. If it is, I can now check on an Image object of that tile, "peip", if the pixel at the player's position is equal to a certain color and execute code if thats the case.

Now where is my problem?
Well, when the hitbox of the player is laid over 2 Backgroundtiles at once, as it naturally happens, the wanted coordinate is larger (in y position) than the image is in height thus returning false for the color check (as some random junk from another memory adress comes out). After a lotta time debugging (yes, with cout) I came to the conclusion that nTop is not being updated before the player is for a hundred percent on the next tile.

May I show you the output of the "debugger"?

Spieler track-380
256   472
Spieler track-380
256   474
Spieler track-380
256   475
Spieler track-380
256   477
Spieler track-380
256   478
Spieler track-380
256   480

Till here it all works fine. The 2 Numbers are the calculated pixel position (x,y - the image is 480px in height).
The 380 is the position of the upper background tile.

Spieler non track 2
non track means the player isnt in the wanted pixel-color area (2 is the sprite number)
       
  NOT 840  20  -380

this is the following seperated 3 Values: playerPosition.y + half its texture length (for centering, I know there are better collision detection solutions its just a prototype) MINUS the background track position. As you can see, here lies the problem: Normally, It _should_ be updated to the new sprite position, which is -860. And sometimes, it gets updated??!?



256   481
Spieler non track 2
       
  NOT 841  20  -380
256   1
Spieler track-860
^^ like here?? ^^
256   483
Spieler non track 2
       
  NOT 843  20  -380


And sometimes not. Its really buggy. Of course I could just write "modulo 480" and the bug would go away, but I really wanna understand why it updated nTop as it pleases. One could say it bugs me personally in a way.

Have a nice day
Cron

7
General / Re: Too dumb for OOP
« on: April 29, 2020, 03:27:57 pm »
Hello!
Thank you, solution 1 indeed does work, as I found out on my way to the minimum example. I was still giving the Texture Map to the poop class, and that, as you said, destroyed it!

Of course, if you dont want to destroy the map, you have to pass its adress. So the poop Constructor just changed to
poop(std::map<std::string, std::unique_ptr<sf::Texture>>* textures){ }

And the call just changed to
    poop obj(&textures);


The loadTexture function does indeed work now, too?!

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


Sorry, maybe I forgot to explain something, but calling the function like this surely doesnt dereferences the pointer?!


(Yee that isSmooth() thing really was desperate :-[)

Thanks for helping :)

Best regards
Cron

8
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???


9
SFML projects / Re: Titanion Clone
« on: April 25, 2020, 03:33:37 pm »
Haha, i like the graphics!
Both the grid optics and the techno theme remember me of the 2001 released "REZ" for the Dreamcast - look it up, its amazing!

10
SFML projects / Re: My first coding program: Xenon
« on: April 25, 2020, 12:44:30 pm »
Yo I found an error lol im sorry this is my first post :see_no_evil:

Quote
void SoundManager::fxVolumeDown() {
    if(fxVolume > 0) {
        playNavigationSound();
        fxVolume--;
        for (const auto &i : soundAtlas)
            soundAtlas[i.first].setVolume((float) fxVolume);
    }

You see? You are first playing the sound and then reducing it.


Nevertheless of course a great game  :D

Pages: [1]
anything