Tiled graphix vs. canvas vs. dip

WizardOz

Member
Licensed User
Longtime User
Ok, I have a game-thingy-design that calls for tiled graphix.
For those who dont know what tiled graphics is, lets think of old Zelda-games. The background was made of blocks of graphixs, so you could re-use blocks to save memory and re-arange the blocks to make other scenery.

The tiles I am using are copied from a bitmap, and are in the size of 32x32pixels (real oldschool :) )
The design calls for 15x15 tiles. So the number of pixels should be 32x15=480.

This is all fine, I use the following lines to copy the tiles into the canvas (the random-bit in the code inside is just temperary ofcourse):

B4X:
   Dim ran As Int
   Dim Bitmap1 As Bitmap
   Bitmap1.Initialize(File.DirAssets, "Tiles.png")
   For y=0 To    14
      For x=0 To 14
         ran = Rnd(0,6)*32
         SrcRect.Initialize(ran,0,ran+32,32)
         DestRect.Initialize(x*32dip,y*32dip,x*32dip+32dip,y*32dip+32dip)
      
         gridcsv.DrawBitmap(Bitmap1,SrcRect,DestRect)
      Next
   Next

Its not optimised in any way, but it works for now.

But here comes the problem I was hoping you could help me with.

Scale... Its all about Scale...

480pixels isnt 480pixels on all phones, and scaling has to be aplied. But I cant for the life of me get the scaling to be right for tiled bitmaped graphix.
The bitmap has to be the same size and not streched in the x or in the, but scaled so it still looks like the graphix made in 32x32pixels. It can ofcourse get streched to 18x18 but...
Most of all, the game calls for 15x15 of these blocks put together on the display, without glitches between the blocks.

The above code run on a Samsung Galaxy III will only show 12x15 blocks, because of the scaling. I have tried removing dip's and tried calculating the sizes, but every thing I do makes either glitches between the blocks, or streched bitmaps in one way or the other.

Is there anybody out there having a solution or some pointers to what I can do? :sign0085:
 
Top