many images on a canvas

S

sionco

Guest
Hi, I have 199 small images that move around the screen, the following code draws them correctly, but the transparent background of the png image (imgOid) isn´t transparent, would each have to have it´s own canvas, what´s the best way of doing this:

B4X:
Sub Timer1_Tick

   Dim i As Int
   For i = 0 To 199 '200 images and ´rects´
      
      
      oidCanvas.DrawRect(Rect2(i),Colors.Transparent,True,1)
      Activity.Invalidate2(Rect2(i))
      Rect2(i).Top = oids(i).y
      Rect2(i).Left = oids(i).x
      Rect2(i).Bottom = oids(i).y + pSize
      Rect2(i).Right = oids(i).x + pSize
      oidCanvas.DrawBitmap(imgOid,Null,Rect2(i))
      Activity.Invalidate2(Rect2(i))
      
      If oids(i).x + pSize > 99%x Then
         oids(i).vx = -1 
      Else If oids(i).x < 1%x Then
         oids(i).vx = 1
      End If
      If oids(i).y + pSize > 99%y Then
         oids(i).vy = -1 
      Else If oids(i).y < 48 Then
         oids(i).vy = 1
      End If
       oids(i).x = oids(i).x + oids(i).vx
       oids(i).y = oids(i).y + oids(i).vy
         
   Next
   
      
      

      
End Sub
:sign0104:
 
S

sionco

Guest
Hi, a long time in my reply :), but-

the background of the png image is transparent:
gr1.png

and here are two screenshots, which show the green men overlapping each other

screenshot2.jpg
screenshot1.jpg
 
Last edited by a moderator:
Upvote 0

klaus

Expert
Licensed User
Longtime User
What do you mean with 'overlapping' ?

When you draw the 200 images it seems that you want to remove the image from the previous set with this line:
B4X:
oidCanvas.DrawRect(Rect2(i),Colors.Transparent,True,1)
Do you really want to remove these images one after the other ?
You could 'erase' them all once drawing a rectangle on the whole screen.

The transparency of your image is OK.
In the attached test program shows it. Moving the finger moves the image.

Best regards.
 

Attachments

  • TestImage.zip
    6.4 KB · Views: 183
Upvote 0
Top