SFML 2.0:problem in convert program from 1.6 to 2.0

Started by
0 comments, last by nickme 12 years, 1 month ago
hi,

i had written a small program to test out the mouse function before adopt it to a bigger program.

the problem with my program is that no matter where i click the mouse i clicked in the open window, the position.x and .y always return zero. even i put a variable 'i' to set a condition to break out the loop, it did not get out the loop. why the event stack is not popped?

here is the program: thanks

#include <stdio.h>
#include <SFML\graphics.hpp>
#define BOARD_X_SIZE 7

void placeInColumn(const sf::RenderWindow &input) {
int column;
int i = 0;
sf::Vector2i position;
do {
i++;
if (i > 10) break;
if (sf::Mouse::IsButtonPressed(sf::Mouse::Left)) {
position = sf::Mouse::GetPosition();
column = position.x/input.GetWidth()*BOARD_X_SIZE+1;
printf(" px:%f\tpy:%f\tcolumn:%i\n", position.x, position.y, column);
break;
}
} while (true);
}

int main(int argc, char *argv[]) {

sf::RenderWindow app(sf::VideoMode(600, 400, 32), " my sfml 2.0 test");

while (app.IsOpen()) {
sf::Event Event;
while (app.PollEvent(Event)) {

if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
app.Close();
if (Event.Type == sf::Event::Closed)
app.Close();
}
placeInColumn(app);
}

return 0;
}
Advertisement
hi

now i know what the problem was. it was because i print out the float %f instead of %i.

bye.

This topic is closed to new replies.

Advertisement