hi i'm trying make little ufo bitmap (drawing/painting taken care of) can dragged around screen. can't seem make ufo position update , redraw repeatedly mousebuttondown() function (simplified code mouse event handler). suggestions on detecting dragging , redrawing accordingly? code below relevant functions:
void mousebuttondown(int x, int y, bool bleft) { if (bleft) { while(_bmousemoving == true && _bmousedragrelease == false) { _isaucerx = x - (_psaucer->getwidth() / 2); _isaucery = y - (_psaucer->getheight() / 2); invalidaterect(_pgame->getwindow(), null, false); } // set saucer position mouse position _isaucerx = x - (_psaucer->getwidth() / 2); _isaucery = y - (_psaucer->getheight() / 2); } else { // stop saucer _ispeedx = 0; _ispeedy = 0; } } void mousebuttonup(int x, int y, bool bleft) { _bmousedragrelease = true; } void mousemove(int x, int y) { _bmousemoving = true; }
to clarify chris said, you're going wm_xbuttondown message once, , you'll need use toggle dragging state can query when recieve wm_mousemove message.
when mouse move message during dragging state, you'll want invalidate rectangle surrounding ufo was, , rectangle surrounding is.
invalidating rectangle causes wm_paint messages, redraw whatever behind ufo, , ufo in it's new place.
or cheat , make ufo cursor when you're dragging :)
Comments
Post a Comment