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

Pages: [1]
1
Graphics / Re: Graphical glitch appearing
« on: March 31, 2025, 12:33:06 am »
Allright, I am sorry for late response.
I am not exactly sure what happened, but I copied my up to date code. Rollbacked project few weeks the issue disappeared... Applied updated code, still couldn't reproduce the bug.
So yeah, it seems like there was something gnarly going on with project tree most likely, I have no idea what, maybe some stray include(that is my educated guess).

2
Graphics / Re: Graphical glitch appearing
« on: March 03, 2025, 11:00:46 pm »
I made a mistake, I actually store sf::Texture in class as unordered map, like so:
Quote
class ResourceManager
{
public:
    ResourceManager();



    sf::Texture* load(std::string _path);
    sf::Texture* get(std::string _path);

private:
    std::unordered_map<std::string, std::unique_ptr<sf::Texture>> textures_;
};
sf::Texture* ResourceManager::load(std::string _path)
{
   sf::Texture texture_temp;
   if (!texture_temp.loadFromFile(_path))
   {
      std::cerr << "Error loading texture " << _path << std::endl;
      return nullptr;
   }

      textures_[_path] = std::make_unique<sf::Texture>(_path);

   return textures_[_path].get();
}

sf::Texture* ResourceManager::get(std::string _path)
{
   return textures_[_path].get();
}
I also attached second screenshot. My bad should have double checked things.

3
Graphics / Graphical glitch appearing
« on: March 03, 2025, 06:35:48 am »
Hello, I experience graphical glitch. I attached 2 screenshots, 1 with and 1 without graphical bug.
minimal code looks something like so
Quote

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
sf::Texture default_texture("my default texture.png");
struct Sprite
{
    explicit Sprite() {}
    explicit Sprite(const sf::Texture& _texture) : sprite_(_texture) {}
    std::optional<sf::Sprite> sprite_ = std::nullopt;
};
Sprite first_sprite;
std::vector<Sprite> sprites;

  void init()
      {
        first_sprite.sprite_->setTexture(default_texture);
        for (int i =0; i < 5;++i)
        {
          sprites.push_back(first_sprite);
        }
    }
int main()
{
    //init

    sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML window");
    init();
    while (window.isOpen())
    {
        while (const std::optional event = window.pollEvent())
        {
            // Close window: exit
            if (event->is<sf::Event::Closed>())
                window.close();
        }
        window.clear();
        for (int i =0; i < sprites.size(); ++i)
        {
          if (sprites.sprite_.has_value())
          {
            window.draw(sprites.sprite_.value());
          }
        }
        window.display();
    }
}
Whether or not the glitch appears I seem to be able to reliable reproduce based on the size of vector of sprites. (For examples I push_back 5 Sprites it appears, I do 7 it doesn't.
 
The wrapper for sf::Sprite is necessary I can't go around it.
OS: archlinux
Why is this happening? What might be the cause? I am at loss here, I seem to be lacking some knowledge. Might be because I copy the sprite, but I had no issue in the past.

4
So I noticed something really weird. Passed sprites object has both width and height of 0.
so for example when I call my collision function and cout: mleczny->sprite.getGlobalbounds.height;
it will display zero, but for "this" pointer it gives correct parameters.
I think that passing object of my class somehow that object starts reffering to empty sprite ?

5
Hello everyone,
So I had class A, and class B, and external function that would check collision for me. It looked something like that
bool collision(*A a, *B )
{
  if (a->sprite.getGlobalBounds().intersects(b->sprite.getGlobalBounds()) &&
                b->sprite.getGlobalBounds().intersects(a->sprite.getGlobalBounds()))
       {
return true;
        }
}
then I made parent class and put checking collision there
bool collision(parentclass *mleczny)
{
if (this->sprite.getGlobalBounds().intersects(mleczny->sprite.getGlobalBounds()) &&
                mleczny->sprite.getGlobalBounds().intersects(this->sprite.getGlobalBounds()))
{
 return true;
}
}
but after using it on my subclass A
 a.collision(&b);
it keeps returning false. Also I had few other functions that I used in both classes and put them into my parent class and they work just fine!

Pages: [1]