Gameview - add a list of BitmapData?!

Quillok

Member
Licensed User
Longtime User
Hi,
I'm doing my first steps with gameview, I think I know how it works and how to use it, but I've got a little problem.

As I've seen you add the different bitmaps to the gameview, which will be redrawn in invalidate.

Now I have some bitmaps I want to be drawn in gameview, but did I have to set for each one a bitmapdata?

This code works:

B4X:
Dim GV as GameView
Dim BD, BD2 as BitmapData

GV.initialize("GV")
Activity.AddView(GV,0,0,100%x,100%y)

BD.Bitmap = LoadBitmap(File.DirAssets,"test.png")
BD.DestRect.Initialize(50dip,50dip,100dip,100dip)
BD2.Bitmap = LoadBitmap(File.DirAssets,"test2.png")
BD2.DestRect.Initialize(100dip,100dip,150dip,150dip)

GV.BitmapsData.Add(BD)
GV.BitmapsData.Add(BD2)
GV.invalidate

If I add the single BitmapData object into a list it works again:

B4X:
Dim GV as GameView
Dim BD, BD2 as BitmapData
Dim BDList as List

BDList.Initialize
GV.initialize("GV")
Activity.AddView(GV,0,0,100%x,100%y)

BD.Bitmap = LoadBitmap(File.DirAssets,"test.png")
BD.DestRect.Initialize(50dip,50dip,100dip,100dip)
BD2.Bitmap = LoadBitmap(File.DirAssets,"test2.png")
BD2.DestRect.Initialize(100dip,100dip,150dip,150dip)

BDList.Add(BD)
BDList.Add(BD2)

GV.BitmapsData.AddAll(BDList)

GV.invalidate

But I've got an unknown amount of bitmaps that will be added to the gameview, so I tried this and it does not work, only the last added bitmap will be drawn. I'm not sure where the problem is, maybe it's not possible to use it as I planned it, but maybe the is only a small mistake I did not see, so if anybody could help it would be wonderful

B4X:
Dim GV as GameView
Dim BD, BD2 as BitmapData
Dim BDList as List

BDList.Initialize
GV.initialize("GV")
Activity.AddView(GV,0,0,100%x,100%y)

BD.Bitmap = LoadBitmap(File.DirAssets,"test.png")
For x = 0 To 10
   BD.DestRect.Initialize(50dip,50dip+(50dip*x),100dip,100dip+(50dip*x))
   BDList.Add(BD)
Next

GV.BitmapsData.AddAll(BDList)
GV.invalidate

I understand why it only draws the last one, because I'm overwriting the BitmapData where the previous Bitmaps was in. And thats my problem, I have no idea how to manage this, that I can draw an unknown number of bitmaps to the gameview without dim an extra bitmapdata for each :/
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…