Jump to content
  • Advertisement
Sign in to follow this  

SFML 2.0:problem in convert program from 1.6 to 2.0

This topic is 2780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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 {
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);
} 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))
if (Event.Type == sf::Event::Closed)

return 0;

Share this post

Link to post
Share on other sites

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


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!