1
General / Re: [WIN7] Odd problem with std::cout
« on: January 26, 2013, 04:25:18 am »int main()
{
//variables
float playerX = 400;
float playerY = 300;
float mouseX = 0.0;
float mouseY = 0.0;
double dx = 0;
double dy = 0;
float trigresult = 0.0;
//shapes
sf::RectangleShape playerRect;
playerRect.setSize(sf::Vector2f(BLOCK_SIZE,BLOCK_SIZE));
playerRect.setPosition(playerX,playerY);
playerRect.setOrigin(BLOCK_SIZE/2,BLOCK_SIZE/2);
playerRect.setTexture(&tex_playerRect);
//gameloop//////////////////////
while(bPlay == true)
{
//EVENTS//
while(window.pollEvent(event))
{
/////////////////////////////////////
//mouse
//check if mouse moved
if(event.type == sf::Event::MouseMoved)
{
mouseX = event.mouseMove.x;
mouseY = event.mouseMove.y;
}
}
//LOGIC//
//point playerRect at mouse pos
std::cout << mouseX << "\n";
std::cout << mouseX << "\n";
dx = mouseX - playerX;
dy = mouseY - playerY;
trigresult = atan2(dy,dx) * 180/PI;
playerRect.setRotation(trigresult + 90);
//RENDERING//
window.clear();
window.draw(playerRect);
window.display();
}
}
{
//variables
float playerX = 400;
float playerY = 300;
float mouseX = 0.0;
float mouseY = 0.0;
double dx = 0;
double dy = 0;
float trigresult = 0.0;
//shapes
sf::RectangleShape playerRect;
playerRect.setSize(sf::Vector2f(BLOCK_SIZE,BLOCK_SIZE));
playerRect.setPosition(playerX,playerY);
playerRect.setOrigin(BLOCK_SIZE/2,BLOCK_SIZE/2);
playerRect.setTexture(&tex_playerRect);
//gameloop//////////////////////
while(bPlay == true)
{
//EVENTS//
while(window.pollEvent(event))
{
/////////////////////////////////////
//mouse
//check if mouse moved
if(event.type == sf::Event::MouseMoved)
{
mouseX = event.mouseMove.x;
mouseY = event.mouseMove.y;
}
}
//LOGIC//
//point playerRect at mouse pos
std::cout << mouseX << "\n";
std::cout << mouseX << "\n";
dx = mouseX - playerX;
dy = mouseY - playerY;
trigresult = atan2(dy,dx) * 180/PI;
playerRect.setRotation(trigresult + 90);
//RENDERING//
window.clear();
window.draw(playerRect);
window.display();
}
}
I hope this is enough code for you to help(also note that the first std::cout for mouseX didn't actually output anything to the console, but when I inserted it twice it worked ( )