Hi PlayerSquared, today I present to you my smooth scroll code.
ASM
C
ASM
Code:
:SmoothScroll_ //(float destinationCoord, float currentCoord)
Function 2 5 0
getF1 0
setF1 5
getF1 1
JumpFalse @EndSmoothScroll_
getF1 0
getF1 1
JumpLT @SubFromScrollbarCoord_
getF1 0
getF1 1
JumpGT @AddToScrollbarCoord_
Jump @EndSmoothScroll_
:SubFromScrollbarCoord_
getF1 1
getF1 0
fSub
fPush 0.007
JumpLE @EndSmoothScroll_
getF1 1
getF1 1
getF1 0
fSub
fPush 1.7
fDiv
fSub
setF1 5
Jump @EndSmoothScroll_
:AddToScrollbarCoord_
getF1 0
getF1 1
fSub
fPush 0.007
JumpLE @EndSmoothScroll_
getF1 1
getF1 0
getF1 1
fSub
fPush 1.7
fDiv
fAdd
setF1 5
:EndSmoothScroll_
getF1 5
Return 2 1 //scrollbarCoord
C
Code:
float SmoothScroll(float destinationCoord, float currentCoord)
{
float newCoord = destinationCoord;
if (!(currentCoord == 0.0f))
{
if (destinationCoord < currentCoord)
{
if (!(currentCoord - destinationCoord <= 0.007f))
{
newCoord = currentCoord - (currentCoord - destinationCoord) / 1.7f;
}
}
if (destinationCoord > currentCoord)
{
if (!(destinationCoord - currentCoord <= 0.007f))
{
newCoord = currentCoord + (destinationCoord - currentCoord) / 1.7f;
}
}
}
return newCoord;
}
Last edited by a moderator: