Posted Mon Jun 26, 2006 11:23 AM
The problem with different constants is that you will get some degree of jerkiness in the motion.
But, to implement smooth transition in velocity, here's a technique I like to use.
Have a velocity byte for movement (scrolling, player left-right speed, whatever):
bit 7 = direction
bits 6-3 = fractional value. Maintain a seperate counter value which this number gets added to each frame. In the event that the counter goes negative (ie - bit 7 set), then add one to the velocity value for that frame only.
bits 2-0 = velocity value - value from 0 to 7 which gets added/subtracted from positional value each frame.
Having such a layout allows simple operations.
Firstly, AND out direction and velocity, then add to the counter.
Bit 7 of the counter will goto 1 if the counter overflows... so just PHP to save the overflow state. AND the new counter value with #$78 and store back in.
Next, get your velocity byte, branch to the relevant add or subtract code dependant on the N flag (bit 7)... then AND #7 to get the velocity value only, then PLP to get the overflow status from the counter.
Now if the N flag is set, you have to set (for add) or clear (for subtract) the carry. Then do your add/subtract from XPos, Scroll value, whatever.