• Advertisement
Sign in to follow this  

Polling for the mouse too fast. (SDL/VS10)

This topic is 2773 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

What I want to do boils down to moving a box from left to right on a 2d surface. Literally click on the box, drag it, then release when the button is released. Sounds simple enough.

The problem arises for me when I want other things to continue happening while the box is being moved (other sprites animating, dynamically, based on the box's position, other things unrelated) and the fact that the box can't move pixel-to-pixel...he has to move from one box-sized *tile* to another. So if you haven't moved the cursor far enough, it shouldn't move at all. The box should only move if the cursor has effectively moved a box-length.

Now, I can't just base the box's position on the mouse's position, because there are obstacles between and you can still pull the box even if it gets stuck on something and the cursor gets ahead of it (like gravity). So I'm down to polling time.

If I pole too frequently, the user won't be able to practically move the mouse fast enough to evoke a response in the box. If I pole to slowly, I'm worried the box and/or other events may suffer (and it may get frustrating, but I feel like I can work that out at least experimentally). Here are some solutions I'm playing with (but not confident about).

- Global delay (literally DELAY(N)). I hate this idea.
- Global delay for all event polling. I'm equally opposed to this idea.
- Delay polling for the box movement only: that is, I don't send any messages to the box after the first unless a certain amount of time has elapsed. This would apply to MOUSEMOTION events - not to BUTTONUP/DOWN events. Not sure how long to wait though.

This seems like something common enough that others have likely confronted it, so here I come looking for input. Of my three ideas, the last one seems the most likely to me. I welcome advice; thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement
Sounds like you should let the mouse go wherever the user wants to move it, move the box towards the mouse, and use line probes or some other physical test to prevent the box from going through obstacles.

Share this post


Link to post
Share on other sites
I do want the user to move the mouse as they wish, but I want the speed that the mouse cursor has impact on the speed of the box.

Am I confused about this polling/timing issue? Do you not think it's an issue?

Share this post


Link to post
Share on other sites
The box has speed? I thought you said it snapped to tiles?

I think that I don't have a complete idea of what you are trying to do :/

Share this post


Link to post
Share on other sites
The NDA makes it hard to explain; my analogy failed. =
Nevertheless, I think I figured it out. I simply wasn't keeping enough state. By keeping only the (x,y) positions at the current and previous polling, I was introducing this problem. If I keep current, previous, and the first postition (where the move started) I can then track both distance moved and (effectively) acceleration. Thanks for trying to help me, despite me being painfully vague. <_<

Share this post


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

  • Advertisement