Android Question Unexpected results when moving around imageviews

Polaris

Member
Licensed User
Longtime User
I"m getting this odd behavior when I move imageviews around. I've tried everything but it's got me stumped, so any help would be appreciated.
So I have this cross platform card game as a B4X pages project. I'm doing all the coding and testing in B4j for now. The problem is this : When I move a set of cards (selected by the player) to another part of the screen (A) all goes well, if I reverse the operation and put them back to their original position, all goes well. If I move the set to another spot on the screen (B) again all goes well both back and forth. But if I move the set first to position (A) then to (B) then back to their original position the cards end up out of place. If I eliminate the step by step animation effect and move the cards directly back to their original position in one move it also works fine. So why does the step by step animation mess up only when the set moves from A to B before returning to the original positions. ???


Shift A set OF CARDS from the grid to position A ( This works just fine ):
    Dim movestepUp , moveStepOver As Int
    NumberSteps = 18
    Dim j As Int
 
    For i = 0 To 4
        J = Panes.get(i)              ' ( Panes is a List that contains the ID number of the Imageviews contained in the Array called Views )
     StartPos(i) = Views(j).Left     ' ( Views(is an Array of Imageviews)
     StartPos(i+5) = Views(j).Top
   
 
        movestepUp = (DiscardTop - Views(j).Top) / NumberSteps
        moveStepOver = (DiscardLeft - Views(j).Left) / NumberSteps
   
          For k = 1 To NumberSteps
            Views(j).Left = Views(j).Left + moveStepOver
            Views(j).Top = Views(j).Top + movestepUp
          Sleep (2) '
        Next
 
      Next


This is the code that moves the set of cards back to the original position in the grid:
Sub Deal_Out
    Dim NumberSteps As Int = 18
'    Dim PosLeft As Int
'    Dim PosTop As Int
    Dim movestepUp , moveStepOver As Int
    Dim j As Int
       
    For i = 0 To 4
       j=Panes.Get(i)
       Views(j).Left = 310     ' ( Here i move the set of cards to position (B) instantly without animation)
       Views(j).Top = 740
       moveStepOver = (StartPos(i)- Views(j).Left ) / NumberSteps       (StartPos is an Array that contains the the original coordinates on the grid ofn the cards being moved.)
       movestepUp = (StartPos(i+5)- Views(j).Top ) / NumberSteps
 
   
       For k = 1 To NumberSteps
           Views(j).Left = Views(j).Left + moveStepOver
           Views(j).Top = Views(j).Top + movestepUp
 
'           Views(j).Left = StartPos(i)                    This part is commented out, i used it to test moving the cards back to their original position on the grid without  
'           Views(j).Top = StartPos(i+5)                moveStepOver animation , and doing it this way it works fine ,  buti i need the animated movment to make it look real. 
           Sleep(3)
       Next
    Next

   Panes.Clear
Reset
 
End Sub
 

Attachments

  • IMG_20260425_124640 (2) (2) (1) (1).jpg
    287.6 KB · Views: 38
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…