Mouse Pausing
From TDN
Original Question:
When I click, it pauses movement for some reason.
function sceneWindow2D::onMouseMove( %This, %Modifier, %WorldPosition, %MouseClicks )
{
//get mouse positions
$mxpos = getWord(%WorldPosition,0);
$mypos = getWord(%WorldPosition,1);
UpdatePlayer();
}
Thats my mouse handling code - someone on these forums told me how it was done, however, when I click, it pauses movement for some reason? Am I doing the right thing, as this is an entirely mouse-driven game?
TIA,
Rob
Answer:
Nothing wrong with that code.
When you click the mouse and move, it produces "onMouseDragged()" or "onRightMouseDragged()" events, not "onMouseMove()" at that point. You can put the same code in the dragged call as well if you wish (example below).
Also, I´d definately recommend not splitting-up the X/Y components until you have to. No need doing more work and having more variables than you have to. Also, you don´t need to store the players position or use globals to transfer stuff like this. Most of the time these variables will be out of date so they are just overhead and confusing.
Just use something like:-
// Mouse Move.
function sceneWindow2D::onMouseMove( %This, %Modifier, %WorldPosition, %MouseClicks )
{
UpdatePlayer( %WorldPosition );
}
// Click and Drag.
function sceneWindow2D::onMouseDragged( %This, %Modifier, %WorldPosition, %MouseClicks )
{
UpdatePlayer( %WorldPosition );
}
// Update Player.
function UpdatePlayer( %WorldPosition )
{
myPlayer.setPosition( %WorldPosition );
}
// Where is my player?
echo( myPlayer.getPosition() );
- Melv.



