Games [XUI2D] BitmapCreator drawing methods

Erel

B4X founder
Staff member
Licensed User
Longtime User
Edit: New tutorial covering features added in v4.50: https://www.b4x.com/android/forum/posts/622812/


BitmapCreator v4.30 was released: https://www.b4x.com/android/forum/threads/b4x-xui2d-box2d-game-engine.95208

This version adds several new drawing methods:
DrawLine, DrawRect and DrawCircle.

SS-2018-10-11_14.48.12.png


Drawings are antialiased and with good performance.
The main advantage of drawing with BitmapCreator directly is that the conversion: Canvas -> Bitmap -> BitmapCreator is not needed. This can save precious time inside the game loop.

Like many things related to programming, writing a simple function that draws a 1-pixel, aliased line is simple. However drawing a thick, antialiased line with bounds checking and with good performance is much more difficult. If anyone is interested the source code is attached (use the library instead of the source code).

More methods will be added if developers find it useful.
 

Attachments

  • BitmapCreator.bas
    74.3 KB · Views: 528
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   Private MainForm As Form
   Private Pane1 As B4XView
   Private ImageView1 As B4XView
   Private xui As XUI
   Private bc As BitmapCreator
   Private px, py As Float
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1")
   MainForm.Show
   bc.Initialize(ImageView1.Width, ImageView1.Height)
End Sub

Sub Pane1_Touch (Action As Int, X As Float, Y As Float)
   If Action = Pane1.TOUCH_ACTION_DOWN Then
       Dim r As B4XRect
       r.Initialize(x - 20, y - 30, x + 20, y + 30)
       bc.DrawRect(r, Rnd(0xff000000, -1), False, 5)
       bc.DrawCircle(X, Y, Rnd(10, 20), Rnd(0xff000000, -1), False, Rnd(1, 30))
       bc.DrawLine(px, py, X, Y, xui.Color_Red, 3)
       ImageView1.SetBitmap(bc.Bitmap)
       px = X
       py = Y
   End If
End Sub

B4J project is attached.
 

Attachments

  • 1.zip
    1.8 KB · Views: 512

ilan

Expert
Licensed User
Longtime User
Yes. However it is not related to the new drawing methods. You can draw or load a bitmap and attach it to a body. The simplest way to do it is with Tiled editor.

Instead of storing lots of pngs i 2ould like to create a shape and attach a body to it. For example i want to create lot of colorful balls so with a shape object like u have in libgdx or spritekit u can use it and create in any color and use as your ball or wall or ground. The benefit here is that i dont need to have multiple pngs of the same image with only different colors.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Instead of storing lots of pngs i 2ould like to create a shape and attach a body to it. For example i want to create lot of colorful balls so with a shape object like u have in libgdx or spritekit u can use it and create in any color and use as your ball or wall or ground. The benefit here is that i dont need to have multiple pngs of the same image with only different colors.
There are many things that you can do and you don't need a bitmap file for each body. Please start a new thread for further discussion.
 
Top