Yes it is. You will want to be using floats to do that tough.
What you need to do is to calculate the direction vector. And then normalize that vector and multiply it by speed and delta time.
//vector classclass vec2{ public float x; public float y;};// normalize it, means makeing the lenght of it to 1vec2 normalize(vec2 v){ // calc the lenght of a vector float m = sqrt(v.x*v.x + v.y*v.y); if(m > 0.0f) m = 1.0f / m; else m = 0.0f; vec2 out out.x = v.x * m; out.y = v.y * m; out.z = v.z * m; return out;};
to get the the direction vector, you take the pos of where the object is right now. And where it wants to go.
vec2 sprite_pos;sprite_pos.x = sprite.posX;sprite_pos.y = sprite.posY;vec2 mouse_pos; // where you have clicked and want to go to.mouse_pos.x = mouseposX;mouse_pos.y = mouseposY;vec2 direction = sprite_pos - mouse_pos; // the direction.// normalize it, important.direction = normalize(direction);// now, in your moveTo function. You add the direction into the calculaton of moveX and Y. Like so:moveX = SPRITE_SPEED * delta_time * direction.x;moveY = SPRITE_SPEED * delta_time * direction.y;
I wrote this code from memory, so im not 100% sure normalization func is correct. But i think so. Otherwise just google for vector normalization.