I've done queries before regarding image quality for sprites and I don't see the light at the end of the road yet. I have tried what is indicated in indicated in the following link (https://www.b4x.com/android/forum/t...lking-character-solution.136579/post-864221), which does improve but not much, and also tried to reduce the imagen (.png) resolution pixels so that it remains at the same resolution according the relationship of the each patterns as the one configured in tiled (it also improves a bit but it is far from being a good image quality), so I started to review the source code of the X2 library regarding X2.ReadSprites and X2.GraphicCache.PutGraphic, in order to see if I could play around with any relevant variables that might come up with a solution to poor sprite quality.
If I think I'm right, these are the classes that capture the variables for creating the sprite graphics.
Inside X2Utils:
Inside X2SpriteGraphicCache
As I am not familiar with several of the functions that are used in these classes such as "CompressedBC" , "ExtractCompressedBC" and others, so, my interaction attempt to play with the code was not very successful.
I would appreciate any idea to know if from these lines of code of the X2 source library, it is possible to adjust some value that allows me to considerably improve the quality of the sprites and perhaps also of the drawn text when using the following code (the result is also very low quality)
To improve the images of the characters and elements of the Game I have tried a solution and it is to create imageviews dynamically for each object, and make these images follow the position of the objects, and using a bitmap array, load each image from each frame of the sprite .
The visual result of the quality of the imageviews is considerably much better than the sprites drawn by X2, but I think that should not be the solution since I suppose that in the first place it would consume more processor resources when making an ImageView for each object, and Secondly, because I think that the correct thing to do is to use the tools designed for this purpose.
I appreciate Any iddea!
If I think I'm right, these are the classes that capture the variables for creating the sprite graphics.
Inside X2Utils:
B4X:
Public Sub ReadSprites (Bmp As B4XBitmap, Rows As Int, Columns As Int, WidthMeters As Float, HeightMeters As Float) As List
Dim res As List
res.Initialize
Dim scale As Float = mBCPixelsPerMeter * BmpSmoothScale
Dim RowHeight As Int = Bmp.Height / Rows
Dim ColumnWidth As Int = Bmp.Width / Columns
For r = 0 To Rows - 1
For c = 0 To Columns - 1
Dim b As B4XBitmap = Bmp.Crop(ColumnWidth * c, RowHeight * r, ColumnWidth, RowHeight).Resize(WidthMeters * scale, HeightMeters * scale, False)
Dim sb As X2ScaledBitmap
sb.Bmp = b
sb.Scale = BmpSmoothScale
res.Add(sb)
Next
Next
Return res
End Sub
Inside X2SpriteGraphicCache
B4X:
Public Sub PutGraphic(Name As String, X2ScaledBitmaps As List) As X2SpriteGraphicData
Dim sb As X2ScaledBitmap = X2ScaledBitmaps.Get(0)
Dim antialias As Boolean = sb.Bmp.Width / sb.Scale * sb.Bmp.Height / sb.Scale < 3000
If Name.StartsWith(TempPrefix) Then antialias = False
Return PutGraphic2(Name, X2ScaledBitmaps, antialias, 5)
End Sub
'Name - Key
'X2ScaledBitmaps - List or array with the ScaledBitmaps objects.
'AntiAlias - Whether to use antialiasing when rotating the images. Can have a large impact on performace.
'AngleInterval - Default value is 5 degrees.
Public Sub PutGraphic2(Name As String, X2ScaledBitmaps As List, AntiAlias As Boolean, AngleInterval As Int) As X2SpriteGraphicData
#if Not (X2SkipLogs)
Log($"New graphic: ${Name}"$)
#end if
Dim data As X2SpriteGraphicData
data.Initialize
data.Name = Name
data.MapsOfCompressedBCs.Initialize
data.OriginalBCs.Initialize
data.LastUsed = DateTime.Now
For Each sb As X2ScaledBitmap In X2ScaledBitmaps
Dim bc As BitmapCreator
bc.Initialize(sb.Bmp.Width, sb.bmp.Height )
bc.CopyPixelsFromBitmap(sb.bmp)
data.OriginalBCs.Add(bc)
Dim m As Map
m.Initialize
Dim cbc As CompressedBC = bc.ExtractCompressedBC(bc.TargetRect, CBCCache)
m.Put(0, cbc)
data.MapsOfCompressedBCs.Add(m)
data.SizeOfAllCompressed = data.SizeOfAllCompressed + cbc.mBuffer.Length
Next
data.AngleInterval = AngleInterval
data.AntiAlias = AntiAlias
cache.Put(data.Name.ToLowerCase, data)
TotalSize = TotalSize + data.SizeOfAllCompressed
Return data
End Sub
As I am not familiar with several of the functions that are used in these classes such as "CompressedBC" , "ExtractCompressedBC" and others, so, my interaction attempt to play with the code was not very successful.
I would appreciate any idea to know if from these lines of code of the X2 source library, it is possible to adjust some value that allows me to considerably improve the quality of the sprites and perhaps also of the drawn text when using the following code (the result is also very low quality)
B4X:
Dim gname As String = X2.GraphicCache.GetTempName
Dim ShapeSize As B2Vec2 = X2.GetShapeWidthAndHeight(template.FixtureDef.Shape)
ShapeSize.MultiplyThis(X2.mBCPixelsPerMeter)
Dim cvs As B4XCanvas = X2.GraphicCache.GetCanvas(ShapeSize.X / X2.BmpSmoothScale)
cvs.ClearRect(cvs.TargetRect)
Dim text As String = Score
Dim r As B4XRect = cvs.MeasureText(text, ScoreFont2)
Dim BaseLine As Int = ShapeSize.Y / 2 - r.Height / 2 - r.Top
cvs.DrawText(text, ShapeSize.X / 2, BaseLine, ScoreFont2, xui.Color_yellow, "CENTER")
Dim sb As X2ScaledBitmap
sb.Bmp = cvs.CreateBitmap.Crop(0, 0, ShapeSize.X, ShapeSize.Y)
sb.Scale = 1
X2.GraphicCache.PutGraphic(gname, Array(sb))
bw.GraphicName = gname
To improve the images of the characters and elements of the Game I have tried a solution and it is to create imageviews dynamically for each object, and make these images follow the position of the objects, and using a bitmap array, load each image from each frame of the sprite .
The visual result of the quality of the imageviews is considerably much better than the sprites drawn by X2, but I think that should not be the solution since I suppose that in the first place it would consume more processor resources when making an ImageView for each object, and Secondly, because I think that the correct thing to do is to use the tools designed for this purpose.
I appreciate Any iddea!
Last edited: