I have been trying to simulate jumping in Small Basic, which I had originally though to be simple but is trickier than I expected. Whenever I try to use animations (or move) in a for loop the program always seems to put whatever delay I have assigned at the start followed by a single animation/move. For example:
GraphicsWindow.Height = 480
GraphicsWindow.Width = 640
pX = 300
pY = 220
GraphicsWindow.KeyDown = KeyPressed
player = Shapes.AddEllipse(40, 40)
Shapes.Move(player, 300, 220)
Sub KeyPressed
If GraphicsWindow.LastKey = "Space" Then
For i = 1 To 10
pY = pY - (10 - i)
Shapes.Move(player, pX, pY)
Program.Delay(100)
EndFor
EndIf
EndSub
I would expect this program to increase the circles why position at a decreasing rate, but instead it waits 1 second (the total number of milliseconds in the loop) and then moves up the whole way at once. How can I achieve what I want and fix this?
The reason is because, it waits for the whole sub to execute then it updates it. what you want is the sub to have a single statement and have the math in a for loop that is calling the subroutine.