OK, good old built-in cEgo.Walk doesn't go very slow. Amaze your firends with your snail-like pace on both objects and characters:
Download here (http://ssh.me.uk/modules/slowmove.zip) (Requires AGS v2.71!) Mirror (http://www.2dadventure.com/ags/slowmove.zip)
--
Edit by strazer: Not needed anymore since AGS v2.72 Beta 3:
* Added ability to use movement speeds slower than 1 (-2 is now 1/2, -3 is 1/3, etc)
--
There are two functions:
slowmove.obj(Object *o, int x, int y, int delay, optional BlockingStyle)
Moves an object from current position to x,y with delay game cycles between each pixel moved
slowmove.cha(Character *c, int x, int y, int delay, optional BlockingStyle)
Moves a character from current position to x,y with delay game cycles between each pixel moved
Default blocking style for both functions is non-blocking
Have fun!
EDIT: Fixed small buglets, documentation, added blocking option and we have version 1.1
Good stuff, a handy workaround for AGS not supporting this :)
I love this!! :D
Just a suggestion but now floats are allowed wouldn't a
slowmove.obj(Object *o, int x, int y, float speed, optional BlockingStyle)
be better, more in line with original move function and more versatile.
Well, if you can tell me how to wait 2.3 game cycles, I'll do it. I call it delay rather than speed, because it is the number of cycles between pixel movements.
Keep a track of the fractional part. Sort of like
Speed=2.3;
and do this every frame
d+=Speed;
delay=FloatToInt(d); // your integer delay for this frame
d-=IntToFloat(delay);
In that case I think it's just more sensible to do just something like:
function UniversalMove(Character *c, int x, int y, float speed, BlockingStyle bs=eNoBlock) {
int sptmp;
if (speed>=1.0) {
sptmp=FloatToInt(speed);
c.SetWalkSpeed(sptmp, sptmp);
c.Walk(x,y,sptmp,bs);
} else if (speed>=0){
sptmp=FloatToInt(1/speed);
slowmove.cha(c, x, y, sptmp, bs);
} else return 1;
}
Good points: actually, I realised the fractional part stuff myself... and Gil, because my code doesn't do walkable areas, I think you'd maybe say WalkDirect and UniversalMoveDirect. But great idea! I'll get around to coding it up sometime...
I ran into an issue: If you sent a "Move" command to the object before it has completed the slow move, this causes an error ("SetPosition can't be set on a moving object").
So perhaps a check to Object.Moving is in order?