Code help - Moving sprite with Activity.ACTION_DOWN

DoogieDog

Member
Licensed User
Longtime User
Almost there. Trying to move a sprite around as I drag my finger on the screen. The sprite is diaplayed and moves, however the previous position is still displayed on the screen, and never gets erased. I guess some more help is needed on the whole canvas and activity invalidate timing. In the old days we used to draw to offscreen then pageflip after each main game llop cycle. How is that applied with invalidate

I have included the prudent code - Thanks Doog

B4X:
Dim screen As Canvas

'-----Draw the Sprite onto the canvas--------
Sub Draw (spr As ddSprite,rct As Rect, canv As Canvas)
   canv.DrawBitmapRotated(spr.img,Null,rct,0)
End Sub

Sub tmr_Tick
   Activity.Invalidate
   animate
End Sub

Sub Animate
   Dim spr As ddSprite
   Dim rct As Rect
   If nextcol > col Then
      nextcol = 0
         NewLevel
   End If
      
   For i=0 To nextcol-1 
      For j = 0 To row -1
         spr=aLevel(i,j)
         rct=aScreenRect(i,j)
         If spr.alive =1 Then
          ddSprite.Draw(spr,rct,screen)
         End If
      Next
   Next
   'DrawPlayerColors
End Sub




Sub Activity_Touch(Action As Int, X As Float, Y As Float)
   'If Not(Action = Activity.ACTION_DOWN) Then Return
   Dim r,c As Int
   Dim spr As ddSprite
   Dim tx, ty As Int
   spr = aPlayerColors(0)
   
   If action= Activity.ACTION_DOWN Then
      tx = X
      ty = Y
      spr = aPlayerColors(0)
      sounds.Play(pop, 1, 1, 1, 0, 1)
      prct.Left = X-24
                               prct.Right = X+24
                               prct.Top = Y-24
                               prct.Bottom = Y+24
      ddSprite.Draw(spr,prct,screen)
      activity.Invalidate2(prct)
   Else
      If action = activity.ACTION_MOVE Then
         prct.Left = X-24
            prct.Right = X + 24
            prct.Top = Y-24
            prct.Bottom = Y+24
         ddSprite.Draw(spr,prct,screen)
         activity.Invalidate2(prct)
      End If
   End If
End Sub
 

DoogieDog

Member
Licensed User
Longtime User
Code .zip file resubmitted with images

Thanks for you help. Here is a new .zip file with images included. D'OH
 

Attachments

  • Bloks.zip
    28.3 KB · Views: 362
Upvote 0
Top