Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite not displayed in the correct position  (Read 2025 times)

0 Members and 1 Guest are viewing this topic.

nikosl21

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite not displayed in the correct position
« on: August 26, 2012, 01:48:52 pm »
When i try to draw a sprite placed in (0,0) inside my gameloop , it isn't drawn properly (but few pixels above and out of app window , i can only  see a part of it ) unless i add these lines before calling window.draw(my_sprite)

while (main_window.GetEvent(currentEvent))
         {
            if (currentEvent.Type == sf::Event::Closed)
               game_state=Exiting;
         }

Does anyone know why it might be happening?
« Last Edit: August 26, 2012, 09:21:33 pm by nikosl21 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: Sprite not displayed in the correct position
« Reply #1 on: August 26, 2012, 02:55:58 pm »
You should read the forum rules, i.e. give a complete minimal example, tell us which OS and which SFML version you're using and which compiler.

The snippet is handling events more specific the close event and they should always be proccessed...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nikosl21

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprite not displayed in the correct position
« Reply #2 on: August 26, 2012, 03:33:35 pm »
I use sfml 1.6 and ubuntu ... i knew what the code snippet was for but i 'd forgotten to add it ..when i saw the wrong placement of the sprite i added it and the problem was fixed but i don't know why ... A complete and simple example in which the same "problem" appears

int main()
{
        // Create the main rendering window
        sf::RenderWindow main_win;
        main_win.Create(sf::VideoMode(1280,1024, 32), "Example");

        sf::Image s;
        if(s.LoadFromFile("src/images/game_start.png") != true)
                std::cerr<<"could not open image";

        sf::Sprite game_start;
        game_start.SetImage(s);
        game_start.SetPosition(0.f, 0.f);

        sf::Event currentEvent;

        while(main_win.IsOpened())
        {
                while (main_win.GetEvent(currentEvent))
                {
                        if (currentEvent.Type == sf::Event::Closed)
                                main_win.Close();
                }
                main_win.Clear(sf::Color(255,0,0));
                main_win.Draw(game_start);
                main_win.Display();
        }
        return EXIT_SUCCESS;
}
 
« Last Edit: August 26, 2012, 09:19:46 pm by nikosl21 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: Sprite not displayed in the correct position
« Reply #3 on: August 26, 2012, 07:40:11 pm »
This forum provides a code=cpp tag which would wrap your code into a box and highlight it as C++ code, please make use of it. ;)

The provided example seems quite similar to the documentation example, so there's actually no reason why it shouldn't work...

On the other hand I strongly advice you to use SFML 2 and abandon SFML 1.6, since it has many bugs and there are already binaries for the SFML 2rc. It may also solve your mysterious problem.

SInce you're on Linux what graphics driver are you using and is it uptodate?
Would it be possible to share an image of the wrongly displayed sf::Image, because I've never had nor heard of such a problem and maybe I'm imagining something wrong. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nikosl21

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprite not displayed in the correct position
« Reply #4 on: September 05, 2012, 11:15:11 pm »
i finally found some time and installed the new version ( sfml2 ) . Everything seems to work fine !
« Last Edit: September 05, 2012, 11:28:39 pm by nikosl21 »

 

anything