Jump to content
  • Advertisement
Sign in to follow this  
beatdown_master

Problems with my drag-and-drop system

This topic is 3682 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)) {	
	    m_DIMouseDevice->Acquire();
	    hr = m_DIMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE), &m_mouseState);
        }//while

        prevMPos = mPos;
        GetCursorPos(&mPos);

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



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;

		    }//else

		}//if
	}//for
    
}//ProcessDragandDrop

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;
                }//if

		TranslateMessage(&msg); 
		DispatchMessage(&msg);
	    } else {
		ProcessInput();
                RenderScene();

	    }//else
	}//while

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!