slowing down a moving object

cammel8

Member
Licensed User
Longtime User
OK, so I am trying to move an image across a panel according to set coordinates I have stored in a list. I am able to get it to move exactly how I want but I can only see the ball move to the finished coordinate. If I iterate through it in debug mode I can see the ball move at each iteration. So I know everything is working but I need to slow down the movement so it looks likes its moving and not just jumping to the new coordinates.

I have tried to use a busy loop so that I can slow it down by an interval I set. but it just pauses the whole app until all iterations are done then moves the image at the end.

Here is the code I am using:

B4X:
Sub cuemove_Click
   
     Dim cuelistnum As Int :cuelistnum=0 
For cuelistnum = 0 To cuelist.Size - 1 'sets a for next loop to size of list

   
     Dim s, xcoordinates, ycoordinates As String 'sets variables needed
     s = cuelist.Get(cuelistnum) 'gets the full x and y coordinates
     xcoordinates = Regex.Split(" ",s)(0)  'extrapolates the x coordinates
     ycoordinates = Regex.Split(" ",s)(1)  'extrapolates the y coordinates
      
     slowdowncue(100) 'pauses animation for x amount of seconds
     cueball_float.Move(xcoordinates,ycoordinates,True) 'moves to coordinates
   
     cuelistnum=cuelistnum+1 'adds one to number for next iteration
Next
   
End Sub
Sub slowdowncue(time As Int)
     Dim timenow As Long 
     timenow = DateTime.Now 'set timenow to present time
     Do While DateTime.Now < timenow + time 'checks to see if ready

Loop
End Sub

For the life of me I cant figure out why its doing this. It should be iterating through the loop getting coordinates, pausing then moving the ball then iterating again. But instead it is starting iteration getting coordinates, pausing, finishing all iterations, moving to final coordinates then un pausing. The more coordinates you have them longer it pauses until it releases the app back to you. Any help would be appreciated. Thanks
 

cammel8

Member
Licensed User
Longtime User
I think you should better use the Animation library (it's a translation animation).


The image I am using is actually the background of a floating window. And is dimmed as a clsFloatingWindow. I don't need the "appearance" of moving I need it to actually move. I actually need it to move to every iteration of the coordinates entered. this way if it hits something in the process i can detect the collision and deal with it accordingly. Can this still be done with the animation library?
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
The image I am using is actually the background of a floating window. And is dimmed as a clsFloatingWindow. I don't need the "appearance" of moving I need it to actually move. I actually need it to move to every iteration of the coordinates entered. this way if it hits something in the process i can detect the collision and deal with it accordingly. Can this still be done with the animation library?

No, in this case, the library is not suited indeed. I'm not competent for games, so I don't know the right libraries for this. I just saw a demo of OpenGL doing this, but it's OpenGL...
To pass the Window as a view to a function expecting a view, use Window.AsPanel.
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
No, in this case, the library is not suited indeed. I'm not competent for games, so I don't know the right libraries for this. I just saw a demo of OpenGL doing this, but it's OpenGL...
To pass the Window as a view to a function expecting a view, use Window.AsPanel.

Well shit, that's not what I wanted to hear. Hehehe. Isn't there any way to just slow down what is happeing in my code without it the code loacking. You figure its already doing what I need it to do now, it is just doing it so fast I cant see it, cause when I debug, it moves to each spot every iteration.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Well shit, that's not what I wanted to hear. Hehehe. Isn't there any way to just slow down what is happeing in my code without it the code loacking. You figure its already doing what I need it to do now, it is just doing it so fast I cant see it, cause when I debug, it moves to each spot every iteration.

Why don't you use Timers ? The move and the collision detection should be made in the timer_tick handler. Thus, you'd control the time between each move precisely.
 
Upvote 0
Top