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

Author Topic: App.Draw() coordinates  (Read 1293 times)

0 Members and 1 Guest are viewing this topic.

Kamaitachi

  • Newbie
  • *
  • Posts: 28
    • View Profile
App.Draw() coordinates
« on: April 13, 2011, 05:43:33 pm »
Why the following code doesn't draw the image in the point defined by (pos1, pos2)?

Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <sstream>
#include <string>

class Field
{
    sf::RenderWindow App;
    sf::Image image;
    sf::Sprite sprite;
    public:
    Field(int x, int y) {App.Create(sf::VideoMode(x, y), "SFML");};
    void FEvent();
    void FDisplay (int, int, std::string);
};

void Field::FEvent ()
{
    while(App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::MouseButtonPressed)
            FDisplay(Event.MouseMove.X, Event.MouseMove.Y, "X.bmp");
        }
    }
}

void Field::FDisplay (int pos1, int pos2, std::string filename)
{
    if(!image.LoadFromFile(filename))
    {
        App.Close();
    }
    sprite.SetImage(image);

    App.Clear();
    sprite.SetPosition(pos1, pos2);
    App.Draw(sprite);
    App.Display();
}

int main()
{
    Field F(315, 315);
    F.FEvent();
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
App.Draw() coordinates
« Reply #1 on: April 13, 2011, 06:02:36 pm »
Because you use Event.MouseMove when a MouseButtonPressed event occured. You must use Event.MouseButton.
Laurent Gomila - SFML developer

 

anything