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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Harsay

Pages: [1]
1
General / Sprite rotation to mouse problem
« on: October 03, 2012, 09:49:48 pm »
Hi.

I've got strange problem with sprite rotation to mouse coords.

sf::Vector2i cursor = sf::Mouse::getPosition(game);
sf::Vector2f worldCursor = game.convertCoords(cursor.x, cursor.y);
sf::Vector2f direction = (worldCursor - Player.getPosition());
Player.setRotation(std::atan2(direction.y, direction.x));
 

Player is not rotating properly.
I found this code on this forum and to compile i need to add sf::Vector2i to worldCursor.

Thanks in advance for help.

2
General / [SFML 2.0] sf::Event::MouseMoveEvent problems
« on: June 17, 2012, 02:29:37 am »
Hi. I have a problem with sf::Event::MouseMoveEvent

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720, 32), "LIKE A PONG TEST", sf::Style::Fullscreen);
    window.setFramerateLimit(60);
    sf::Mouse::setPosition(sf::Vector2i(100, 200), window);
    sf::Event::MouseMoveEvent mouse;
    sf::Event event;
    sf::Text paletka("|");

    while (window.isOpen())
    {
         while (window.pollEvent(event))
         {
             if (event.type == sf::Event::Closed)
                 window.close();

             if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
                 window.close();

             if (event.type == sf::Event::MouseMoved) {
                 int x = mouse.x;
                 paletka.setPosition(x, 5);
                 std::cout << x << std::endl;
             }

         }

        window.clear();
        window.draw(paletka);
        window.display();
    }
}
 

I'm trying to get text x equal to mouse x, but when I am moving the mouse it writes (in cmd) the same x always!
I don't know what to do...

Thanks in advance for help.

Pages: [1]