stefanoa Active Member Licensed User Longtime User Jan 20, 2013 #1 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.. Code: Copy Dim can1 As Canvas Dim bmpActor As Bitmap Dim re(55) As Rect Dim s(55) As Rect ... Code: Copy Sub timerInactivity_Tick actorSpriteMoveInactivity End Sub Code: Copy 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
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.. Code: Copy Dim can1 As Canvas Dim bmpActor As Bitmap Dim re(55) As Rect Dim s(55) As Rect ... Code: Copy Sub timerInactivity_Tick actorSpriteMoveInactivity End Sub Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Jan 21, 2013 #2 Search for DraggableView class. Upvote 0
Informatix Expert Licensed User Longtime User Jan 21, 2013 #3 Erel said: Search for DraggableView class. Click to expand... 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
Erel said: Search for DraggableView class. Click to expand... 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).