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

Author Topic: What am I doing wrong here ?  (Read 2403 times)

0 Members and 1 Guest are viewing this topic.

Xyro

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
What am I doing wrong here ?
« on: November 11, 2009, 11:48:51 am »
I am trying to make a sprite point to the place where I click but it just seems to point upward when I click somewhere, I know it updates the sprite cause in the beginning stage its about 45 degrees and then when I click it points upwards.

Code: [Select]

// The class which needs to update
Cockpit::Cockpit()
{
std::cout << "Cockpit" << std::endl;
    turningspeed = 4;
direction = 0.f;
if (!Image.LoadFromFile("Cockpit.png"))
{
std::cout << "Error loading image file !" << std::endl;
}
sprite.SetImage(Image);
sprite.SetScale(0.5f,0.5f);
float Width  = sprite.GetSize().x;
float Height = sprite.GetSize().y;
sprite.SetRotation(direction);
sprite.SetCenter(Width/2, Height/2);
sprite.SetPosition(400.f,300.f);
x,target_x = 400;y,target_y,y = 300;
}

void Cockpit::Think(sf::RenderWindow &Render)
{
direction = atan2(target_y-y,target_x-x)*180/PI;
sprite.SetRotation(direction);
}
// Inputmanager
void InputManager::Think(sf::RenderWindow &Render)
{
const sf::Input &Input = Render.GetInput();
mouse_x = Input.GetMouseX();
mouse_y = Input.GetMouseY();
mouse_right = Input.IsMouseButtonDown(sf::Mouse::Right);
sprite.SetPosition(mouse_x,mouse_y);

if (mouse_right == true)
{
hold_right += Render.GetFrameTime();
}
if (mouse_right == false && hold_right > 0)
{
if (hold_right >= 0.5)
{
hold_right = 0;
std::cout << "Window" << std::endl;
} else {
hold_right = 0;
player->Goto(mouse_x,mouse_y);
}
}

if(Render.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Render.Close();

if((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::Escape))
Render.Close();

if (Event.Key.Code == sf::Key::F1)
{
sf::Image Screen = Render.Capture();
Screen.SaveToFile("screenshot.jpg");
}
}

}


Anybody knows what I am doing wrong ?

 

anything