Hi, i will explain to you my problem, i have a player, i move him with the keyboard. (left,right,up,down)
I use a sprite that i move with the mouse.
The problem is when i move him when i hit a key,
but if i press another key or if i move my mouse,
my player stop moving
Well, the thing i want , is move (like hit the left key) and move my mouse at the same time or
hit another key.
BUT i can hit my left key and use left,middle,right click on my mouse at the same time.
game.cpp
while(fin){
float timer= frameClock.restart().asSeconds(); /// frameClock in game.h
while (f.getWin().pollEvent(f.getEvent())) {
if (f.getEvent().type == sf::Event::JoystickMoved) {
player.moveJ(timer);
}
if (f.getEvent().type == sf::Event::KeyPressed){
player.move(f.getEvent().key.code,timer);
}
}
}
player.cpp
void player::move(int key,float time_r){
sf::Vector2f movement(0.f, 0.f);
if (key == 71) {///gauche
if (sprite.getRotation() == 270)
movement.x -= vitesse;
else
if ((sprite.getRotation() <= 90 || sprite.getRotation() > 270))
sprite.rotate(-vitesse_tourner);
else
sprite.rotate(vitesse_tourner);
}
else if (key== 72) {///droite
if (sprite.getRotation() == 90)
movement.x += vitesse;
else
if (sprite.getRotation() >= 270 || sprite.getRotation() < 90)
sprite.rotate(vitesse_tourner);
else
sprite.rotate(-vitesse_tourner);
}
if (key== 73) {///haut
if (sprite.getRotation() == 0)
movement.y -= vitesse;
else
if (sprite.getRotation() <= 180)
sprite.rotate(-vitesse_tourner);
else
sprite.rotate(vitesse_tourner);
}
else if (key== 74) {///bas
if (sprite.getRotation() == 180)
movement.y += vitesse;
else
if (sprite.getRotation() <= 180)
sprite.rotate(vitesse_tourner);
else if (sprite.getRotation() >= 180)
sprite.rotate(-vitesse_tourner);
}
sprite.move(movement* time_r);
}
void player::moveJ(float time_r) {
sf::Vector2f movement(0.f, 0.f);
if (sf::Joystick::isConnected(id))
{
float x = sf::Joystick::getAxisPosition(id, sf::Joystick::X);
float y = sf::Joystick::getAxisPosition(id, sf::Joystick::Y);
if (x > 1) {
if (sprite.getRotation() == 90)
movement.x += vitesse1;
else {
if (sprite.getRotation() >= 270 || sprite.getRotation() < 90)
sprite.rotate(vitesse_tourner1);
else
sprite.rotate(-vitesse_tourner1);
}
}
if (x < 0) {
if (sprite.getRotation() == 270)
movement.x -= vitesse1;
else
if ((sprite.getRotation() <= 90 || sprite.getRotation() > 270))
sprite.rotate(-vitesse_tourner1);
else
sprite.rotate(vitesse_tourner1);
}
if (y > 1) {
if (sprite.getRotation() == 180)
movement.y += vitesse1;
else
if (sprite.getRotation() <= 180)
sprite.rotate(vitesse_tourner1);
else if (sprite.getRotation() >= 180)
sprite.rotate(-vitesse_tourner1);
}
if (y < -0.01) {
if (sprite.getRotation() == 0)
movement.y -= vitesse1;
else
if (sprite.getRotation() <= 180)
sprite.rotate(-vitesse_tourner1);
else
sprite.rotate(vitesse_tourner1);
}
}
sprite.move(movement * time_r);
}
I want to say something else, in my game have a beetween one and four players.
When i use the joystick, i don't have the problem.
I have try to add a thread nothing seems to change.