Page 1 of 1

Q: Smooth VIEW Movement ?

PostPosted: Mon Jun 23, 2008 8:38 am
by akhad
Ok, here's another Q regarding an often-used game routine. What's the best way to move the game "camera" (view) using an `ease in/out ` spline type movement. eg. you have one actor at top right. Clicking on the actor will then move the view over the actor, makng it central to the whole screen. But using ease in; this will move the camera/view very quickly to the actor, but slowing (easing in) as it reaches the actor.
The kind of thing often seen in menu selections, really.

Re: Q: Smooth VIEW Movement ?

PostPosted: Mon Jun 23, 2008 9:13 am
by DST
use MoveTo

You can just set the coordinates, with two variables, global integers; name them whatever you like.

object>mousebuttondown
Code: Select all
whatever1=x;
whatever2=y;
CreateTimer("view", "timername", timerlength);


I like to use timers to send activation events like this. and of course, using a timer, you only have to have one event in view for all actors to call it to their xy.

In view, on timer:
Code: Select all
MoveTo("Event Actor", whatever1-width/2, whatever2-height/2, 5, "", "");


For the width/height/2 thing, you can substitute real values if you like (if your resolution is 640 x 480 than it would be whatever1-320, whatever2-240), and where i have '5' that is the speed. Also the "", "" have to be there. The first is 'relative to' and the second is 'avoid', but in this case you don't need them. You still need the "", "" though, or you'll get an error.

Should move smoothly. If it doesn't, I owe you a coke!

Re: Q: Smooth VIEW Movement ?

PostPosted: Mon Jun 23, 2008 7:36 pm
by akhad
Hey DST,
Thanks for the code. It does work ok (and there's a point for you) however I'm still stumped regarding the `ease in` part. I'm thinking there is a way to tie the movement to a Cos function or similar math, maybe like some invisible Bezier spline between the current screen centre and the just-clicked actor, with a variable defining the `tightness` of the curve at each end and thus the views speed. Showing my 3D background here I guess, but that's my best description :roll:

Re: Q: Smooth VIEW Movement ?

PostPosted: Mon Jun 23, 2008 8:14 pm
by Thanx
Maybe you could create a path in such a way, so that it creates an ease in + with paths it's easy to add any other moing effect, not just a straight way through, If you know what I mean...

Re: Q: Smooth VIEW Movement ?

PostPosted: Mon Jun 23, 2008 8:51 pm
by DST
If you want a curve, you can use a path, if you want speed change, you can simply change the speed in the MoveTo function.

If you want both, then yes, you'll have to come up with some kinda cos thing.

Using angle/directional_velocity is possible, but very difficult to control.

I don't really know much about trigonometry so i guess i can't help beyond this. :P

Re: Q: Smooth VIEW Movement ?

PostPosted: Mon Jun 23, 2008 11:25 pm
by feral
if you are just moving directly to the actor ( which is what I assume you mean)

I would first , store the initial distance to the actor (on mouse button down)

then start moving toward the actor , checking the NEW current distance each move,
then as the distance decreased use a formulae to simply change the speed according to the new distance

to ease out simply reverse

attached is one way to do it..
ease-in.zip
ged files and data
(11.78 KiB) Downloaded 94 times

uses variables in global code the distance function and moveto function...
there are probably better ways to do it.. but this should give you the general idea..


feral