[A83] Re: Delay Function


[Prev][Next][Index][Thread]

[A83] Re: Delay Function




Keep a counter that is incremented every frame.  Then keep a counter for
each object that is incremented every frame.  When an object's counter
reaches a certain value, move it, then reset the counter.

If you need more fine grained control over when objects can move, such as
3/4 of the frames, then you'll need more than a simple counter.  Fixed point
is useful here.  You use something like bresenham's algorithm to calculate
things.  Take 3/4 of 256, which is 192.  You then add 192 onto the object
counter every frame.  When the counter overflows (carry flag is set), then
move the object:

(starting at 0)
nc = 192
c = 128
c = 64
c = 0
nc = 192
...

This works for any value ranging from 1/256 to 256/256, and is probably even
easier to code than the global frame counter method.

> Yes, I know it has.  However, mine is slightly different.  I dont want
to=20
> halt because I dont want all the sprites to move at that slow speed.
Only=
> =20
> the npc sprites, where as the "space ship" you control can move at the=20
> normal speed.





References: