1
Graphics / calss not drawing a sprite properly
« on: December 21, 2010, 04:53:31 am »
Hi all,
I'm trying to write a class that manages a cursor but I'm getting some weird behaviour and I need some help to see if someone else can figure it out before it drives me insane.
class is defined as follows
In the constructor, I placed a line to draw and display the loaded sprite so that I could make sure that it loaded properly.
when I create a new cursor with the command
the image is displayed in the top left corner of the window for 3 seconds as would be expected but then when I call
it only draws a single white pixel at the mouse location, offest by 10 pixels, rather than my loaded cursor sprite. Ive even loaded a completely black image and the pixel stilll comes up as white.
I'm trying to write a class that manages a cursor but I'm getting some weird behaviour and I need some help to see if someone else can figure it out before it drives me insane.
class is defined as follows
Code: [Select]
class cursor
{
public:
int getCursorX();
int getCursorY();
bool isPressed();
cursor();
void update();
private:
sf::Sprite sprite;
};
cursor::cursor()
{
sf::Image cursor1;
cursor1.LoadFromFile("cursor.png");
sf::Sprite sprite(cursor1);
sprite.SetCenter(10.f,10.f);
myWindow.Draw(sprite);
myWindow.Display();
sf::Sleep(3);
}
int cursor::getCursorX()
{
return myWindow.GetInput().GetMouseX();
}
int cursor::getCursorY()
{
return myWindow.GetInput().GetMouseY();
}
bool cursor::isPressed()
{
return myWindow.GetInput().IsMouseButtonDown(sf::Mouse::Left);
}
void cursor::update()
{
int x=getCursorX();
int y=getCursorY();
sprite.SetPosition((float) (x-10),(float) (y-10));
myWindow.Draw(sprite);
}
In the constructor, I placed a line to draw and display the loaded sprite so that I could make sure that it loaded properly.
when I create a new cursor with the command
Code: [Select]
cursor *-cursorName- = new cursor();
the image is displayed in the top left corner of the window for 3 seconds as would be expected but then when I call
Code: [Select]
-cursorName->update();
it only draws a single white pixel at the mouse location, offest by 10 pixels, rather than my loaded cursor sprite. Ive even loaded a completely black image and the pixel stilll comes up as white.