Advertisement Jump to content
Sign in to follow this  

Problems with my drag-and-drop system

This topic is 3845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am having a problem with my drag-and-drop system for my game. Basically, whenever I drag an object, there is a very noticeable delay between when I move my cursor to when the object snaps to to the cursor. Here's my code:
void ProcessInput() {
        HRESULT hr;

        ZeroMemory(&m_mouseState, sizeof(m_mouseState));
        hr = m_DIMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), &m_mouseState);

        while (FAILED(hr)) {	
	    hr = m_DIMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), &m_mouseState);

        prevMPos = mPos;

	//determine if left mouse button is pressed
	if (m_mouseState.rgbButtons[0] & 0x80) {
            mPressed = true;
	} else {
            mPressed = false;
	    for (int i = 0; i < selectSize; i++) {
                selectables.drag = false;

void ProcessDragAndDrop() {
        long movedX = 0;
	long movedY = 0;

	//go through each selectable item and determine if cursor is selected
	for (int i = 0; i < selectSize; i++) {

            if (mPos.x >= selectables.x && mPos.x <= selectables.x + selectables.width
			&& mPos.y >= selectables.y && mPos.y <= selectables.y + selectables.height) {

		    if (selectables.drag == true) {
                        //if object was dragged, find distance moved and calculate new position
                        movedX = mPos.x - prevMPos.x;
		        movedY = mPos.y - prevMPos.y;

			selectables.x = selectables.x + movedX;
                        selectables.y = selectables.y + movedY;

		    } else {

		        selectables.drag = true;



I'm using DirectX for rendering, my game loop looks like this:
	while (done == false) {
	    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
                if(msg.message == WM_QUIT) {
		    done = true;

	    } else {


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!