Hello there, I don't know if I'm missing something, is there a slight delay with the Events (Mouse) in SFML?
I have a "View", inside I have a VertexArray, and when I'm dragging it, it do so with a very short delay. I don't know if I'm doing something wrong, I need help!
void Render::mouse_moved(sf::Event event) {
sf::Vector2i mouse_position = sf::Mouse::getPosition(window);
if (!is_dragging) {
int loop = (int)(Sprite::viewer_vector.size() - 1);
for (int j = loop; j >= 0; j--) {
if (Sprite::viewer_vector[j]->mouse_in(mouse_position.x, mouse_position.y)) {
if (Sprite::viewer_vector[j] != viewer_interact) {
viewer_interact = Sprite::viewer_vector[j];
}
break;
}
}
int loop_in = (int)(viewer_interact->viewer_interactable_vector.size() - 1);
bool sprite_found = false;
for (int k = loop_in; k >= 0; k--) {
if (viewer_interact->viewer_interactable_vector[k]->mouse_in(mouse_position.x, mouse_position.y)) {
if (viewer_interact->viewer_interactable_vector[k] != sprite_interact) {
if (sprite_is_over) {
sprite_interact->on_out();
}
sprite_interact = viewer_interact->viewer_interactable_vector[k];
sprite_interact->on_over();
sprite_is_over = true;
}
sprite_found = true;
break;
}
}
if (!sprite_found) {
if (sprite_is_over) {
sprite_interact->on_out();
}
sprite_is_over = false;
sprite_interact = NULL;
}
}
else {
sprite_interact->drag(mouse_position.x,mouse_position.y);
}
}
void Sprite::drag(float v1, float v2) {
set_color(255, 255, 0, 255);
if (!dragging) {
x_move = v1 - x();
y_move = v2 - y();
dragging = true;
}
x(v1-x_move);
y(v2-y_move);
//std::cout << name << " start dragging" << std::endl;
}
I believed I used the shortest way to get this done, but I still have some delay