Cool Mouse Effect...

Feb 27, 2010 at 1:21 AM


I've been experimenting some mouse/ camera effects and i came up with this one....


        void gameHolder_MouseMove(object sender, MouseEventArgs e)
            if (lastGamePos == null) lastGamePos =e.GetPosition(gameHolder);
            double difX = e.GetPosition(gameHolder).X - lastGamePos.X;
            double difY = e.GetPosition(gameHolder).Y - lastGamePos.Y;
            _game.Camera.Position.X += difX;
            _game.Camera.Position.Y += difY;
            lastGamePos = e.GetPosition(gameHolder);


Beeing this the mouse move event handler for the canvas containing the game class (gameHolder)...


Very cool effect, easy to implement... u should try it... :)

Feb 27, 2010 at 2:54 AM case u want your camera to return smoothly to previous position after mouse leave canvas add this...

void gameHolder_MouseLeave(object sender, MouseEventArgs e)
            Storyboard sb = new Storyboard();

            DoubleAnimation da6 = new DoubleAnimation();
            da6.To = camStartPos.X  ;
            da6.Duration = tsp3DChange;
            Storyboard.SetTarget(da6, _game.Camera   );
            Storyboard.SetTargetProperty(da6, new PropertyPath("(Node.Position).(X)"));

            DoubleAnimation da7 = new DoubleAnimation();
            da7.To = camStartPos.Y;
            da7.Duration = tsp3DChange;
            Storyboard.SetTarget(da7, _game.Camera);
            Storyboard.SetTargetProperty(da7, new PropertyPath("(Node.Position).(Y)"));




i knew something was


Feb 27, 2010 at 3:12 AM

ok... issue here ...

camStartPos (Balder.Core.Math,Coordinate) must not be assign directly to _game.Camera.Position when storing initial cam position, cause it retains _game.Camera.Position every time it changes..

instead initialize it like this:

            camStartPos.X = _game.Camera.Position.X;
            camStartPos.Y = _game.Camera.Position.Y;


Well...i guess  everyone knew this except me... lol

Feb 27, 2010 at 4:21 AM

last but not the least... view sample here


Feb 27, 2010 at 6:49 AM
Edited Feb 27, 2010 at 6:49 AM


Great to see Balder being used action outside my own computer .. :)