Games [XUI2D] BitmapCreator drawing methods

Discussion in 'Game Development' started by Erel, Oct 11, 2018 at 1:09 PM.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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.

    [​IMG]

    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.
     

    Attached Files:

  2. ilan

    ilan Expert Licensed User

    Can we draw shapes and attach bodies to them?
     
  3. Erel

    Erel Administrator Staff Member Licensed 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.
     
  4. asales

    asales Well-Known Member Licensed User

    Source code of this example, please.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    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), False5)
           bc.DrawCircle(X, Y, 
    Rnd(1020), Rnd(0xff000000, -1), FalseRnd(130))
           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.
     

    Attached Files:

    • 1.zip
      File size:
      1.8 KB
      Views:
      5
    asales likes this.
  6. ilan

    ilan Expert Licensed 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.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice