Sprite movement

stefanoa

Active Member
Licensed User
Longtime User
hi,
what is the best method to create a sprite, with the possibility of movement with touch?

i need of a sprite (ex. a man, composed of 50 images) and i've tried with this code (with spritesheet, canvas and bitmap) and it's ok..
B4X:
Dim can1 As Canvas 
Dim bmpActor As Bitmap  
Dim re(55) As Rect
Dim s(55) As Rect
...
B4X:
Sub timerInactivity_Tick
   actorSpriteMoveInactivity
End Sub
B4X:
Sub actorSpriteMoveInactivity

   '--- display 50 images for sprite movement..
   For i = 0 To 49
      can1.DrawBitmap(bmpActor,s(inc),re(i))
   Next
   Activity.Invalidate 

   inc = inc + 1
   If inc > 49 Then
      inc = 0
   End If

End Sub
but now I need to use the library functions gesturedetector to move it with touch.

Using a panel and a static image (not a sprite) it's ok.. but with a sprite? how can i move ?

or there is another method to make a sprite animated with possibility of movement with touch?

thanks
 

Informatix

Expert
Licensed User
Longtime User
Search for DraggableView class.

This class won't help (it needs a view as Gesture Detector).

To animate a sprite, you could use the AnimationPlus library. It's a far better solution than the one you're using, but the library is a not totally free (donationware).
To move your sprite, bind the Gesture Detector to the activity, then check the X and Y coordinates when you receive an event (onDrag for example). If the X and Y are in the rectangle area of your sprite, you can move the sprite.
Hint: use getPixel of your bitmap to know if the X and Y are on a transparent pixel or an opaque pixel (the transparent parts should not be considered).
 
Upvote 0
Top