SetEffectLifeMode Resets Mouse
by Doug Linley · in Torque Game Builder · 10/16/2005 (6:18 pm) · 6 replies
Hello,
My team is working on a top-down shooter prototype. We're using the mouse for movement but we're having an issue. When there is an explosion, we call setEffectLifeMode, and then the mouse seems to jump to the top left corner of the screen. If we comment out calls to setEffectLifeMode the issue goes away. Does anyone know how to fix this?
Thanks,
Doug L
My team is working on a top-down shooter prototype. We're using the mouse for movement but we're having an issue. When there is an explosion, we call setEffectLifeMode, and then the mouse seems to jump to the top left corner of the screen. If we comment out calls to setEffectLifeMode the issue goes away. Does anyone know how to fix this?
Thanks,
Doug L
#2
And here is the code containing the call to setEffectLifeMode that seems to cause the second problem:
Has anyone had these strange mouse movement problems before?
Thanks,
Gordon
10/16/2005 (8:22 pm)
(...continuing post...)And here is the code containing the call to setEffectLifeMode that seems to cause the second problem:
function createExplosion( %object )
{
// Ignore if object not around anymore.
if ( !isObject(%object) )
return;
// Shockwave Explosion.
%explosion = new fxParticleEffect2D() { scenegraph = zentharSceneGraph; };
%explosion.loadEffect("~/client/effects/shockwave_burst.eff");
%explosion.setPosition( %object.getPosition() );
%explosion.setEffectLifeMode( kill, 0.3 );
%explosion.playEffect();
}Has anyone had these strange mouse movement problems before?
Thanks,
Gordon
#3
Here it is if can help.
Bind:
However I did notice some warp to...problem (happens very rarely) and yes usualy when there is too much effects running at the same time. (but my coding is still poor with T2D, so that may be the reason) :)
10/17/2005 (11:28 am)
Hmmm I am creating a shooter but my mouse code is much simpler than this and it works.Here it is if can help.
Bind:
cursorOff(); playerMap.bind( mouse, "yaxis", handleMouseY ); playerMap.bind( mouse, "xaxis", handleMouseX);
function handleMouseY( %val )
{
//echo( "MouseY" SPC %val );
$MouseY = %val;
$player.setLinearVelocityY( $MouseY );
}
function handleMouseX( %val )
{
// echo( "MouseX" SPC %val );
$MouseX = %val;
$player.setLinearVelocityX( $MouseX );
}However I did notice some warp to...problem (happens very rarely) and yes usualy when there is too much effects running at the same time. (but my coding is still poor with T2D, so that may be the reason) :)
#4
I'm not sure if I could really suggest something to try apart from ensuring that you're getting a good compile when the createExplosion code is in. Perhaps remove all the DSOs first and then try it again.
Kinda' clutching at straws here though, sorry.
- Melv.
10/17/2005 (11:36 am)
That's extremely odd. I see no links between a particle-effect in a scene and the mouse. These are totally seperate systems and neither call or change the other. There are particle effects being used all over the place and this is the first time it's been reported.I'm not sure if I could really suggest something to try apart from ensuring that you're getting a good compile when the createExplosion code is in. Perhaps remove all the DSOs first and then try it again.
Kinda' clutching at straws here though, sorry.
- Melv.
#5
Melv, we were pretty baffled too, as we would not expect those systems to be linked. But that function is very clearly the cause because when we comment it out, the problem goes away.
Thanks again for your responses. Hopefully we can get this figured out.
-Doug
10/17/2005 (11:50 am)
Thanks for the responses guys. We'll try the method you suggest Denis, though Gordon seems to remember some problem he had with binding to the mouse. It may have had something to do with windowed mode.Melv, we were pretty baffled too, as we would not expect those systems to be linked. But that function is very clearly the cause because when we comment it out, the problem goes away.
Thanks again for your responses. Hopefully we can get this figured out.
-Doug
#6
Dennis,
I got your code to work (with slight modification of course). When I originally tried binding the player to the mouse, I was assuming the param to the callback functions were screen coords of the mouse, but now I see it's actually passing a delta to callback functions.
Just wanted to add that this engine rocks. Best engine I've messed with yet.
10/17/2005 (5:16 pm)
Thanks guys.Dennis,
I got your code to work (with slight modification of course). When I originally tried binding the player to the mouse, I was assuming the param to the callback functions were screen coords of the mouse, but now I see it's actually passing a delta to callback functions.
Just wanted to add that this engine rocks. Best engine I've messed with yet.
Torque Owner Gordon Glas
We are trying to implement mouse movement for the player, meaning that as the mouse is moved, the player is moved based on the deltas of the mouse. It works ok, except during a couple different situations. The first problem is if you try to move the mouse at the beginning of the game, the player "warps" to the left side of the screen. The other problem happens when we shoot the enemies (specifically when we are moving the mouse during a call to setEffectLifeMode(kill, 0.3) to kill the particle explosion effect), the mouse "warps" the upper left.
Here is code being used for mouse movement.
It works by setting mouse pos to center of window, then gets the delta when it is moved, then uses delta to move the player.
function initMouse() { $mouseDeltaX = 0; $mouseDeltaY = 0; $gotInitialMousePos = false; $firstTimeMouseMoved = true; lockMouse(true); } function sceneWindow2D::onMouseMove( %this, %mod, %worldPos, %mouseClicks ) { // get center of window in screen coords $screenPosCenter = sceneWindow2D.getWindowPoint("0 0"); $screenPosCenterX = mFloor(getWord($screenPosCenter,0)); $screenPosCenterY = mFloor(getWord($screenPosCenter,1)); if($playr.state == $STATE_ALIVE) { movePlayerWithMouse(%worldPos); } // reset mouse pos to center of window. // this must be done, because if the mouse is on the edge of the window, // and the mouse is moved further from the window, the mouse move coords won't change. Canvas.setCursorPos($screenPosCenterX SPC $screenPosCenterY); } function sceneWindow2D::onMouseDragged( %this, %mod, %worldPos, %mouseClicks ) { // get center of window in screen coords $screenPosCenter = sceneWindow2D.getWindowPoint("0 0"); $screenPosCenterX = mFloor(getWord($screenPosCenter,0)); $screenPosCenterY = mFloor(getWord($screenPosCenter,1)); if($playr.state == $STATE_ALIVE) { movePlayerWithMouse(%worldPos); } // reset mouse pos to center of window. // this must be done, because if the mouse is on the edge of the window, // and the mouse is moved further from the window, the mouse move coords won't change. Canvas.setCursorPos($screenPosCenterX SPC $screenPosCenterY); } function sceneWindow2D::onMouseEnter( %this, %mod, %worldPos, %mouseClicks ) { // get center of window in screen coords $screenPosCenter = sceneWindow2D.getWindowPoint("0 0"); $screenPosCenterX = mFloor(getWord($screenPosCenter,0)); $screenPosCenterY = mFloor(getWord($screenPosCenter,1)); Canvas.setCursorPos($screenPosCenterX SPC $screenPosCenterY); } function movePlayerWithMouse( %worldPos ) { // get mouse pos in screen coords $mouseScreenPos = sceneWindow2D.getWindowPoint(%worldPos); $mouseScreenPosX = mFloor(getWord($mouseScreenPos,0)); $mouseScreenPosY = mFloor(getWord($mouseScreenPos,1)); // get current player pos in screen coords $playerScreenPos = sceneWindow2D.getWindowPoint($playr.getPosition()); $playerScreenPosX = mFloor(getWord($playerScreenPos,0)); $playerScreenPosY = mFloor(getWord($playerScreenPos,1)); // get mouse deltas $mouseDeltaX = 0; $mouseDeltaY = 0; if($mouseScreenPosX < $screenPosCenterX) // mouse moved left { $mouseDeltaX = -($screenPosCenterX - $mouseScreenPosX); } else if($mouseScreenPosX > $screenPosCenterX) // mouse moved right { $mouseDeltaX = $mouseScreenPosX - $screenPosCenterX; } if($mouseScreenPosY < $screenPosCenterY) // mouse moved up { $mouseDeltaY = -($screenPosCenterY - $mouseScreenPosY); } else if($mouseScreenPosY > $screenPosCenterY) // mouse moved down { $mouseDeltaY = $mouseScreenPosY - $screenPosCenterY; } // use mouse deltas to calculate player's new position $newScreenX = $playerScreenPosX + $mouseDeltaX; $newScreenY = $playerScreenPosY + $mouseDeltaY; // convert back to world coords $newWorld = sceneWindow2D.getWorldPoint($newScreenX SPC $newScreenY); $playr.setPosition($newWorld); }