B4J Tutorial Moving Smiley Example

Discussion in 'B4J Tutorials' started by Erel, Nov 18, 2013.

Similar threads

B4A Code Snippet [B4X] Bytes To File
B4A Tutorial [B4X] [XUI] Drawing with B4XCanvas
B4J Tutorial Getting Started Examples
B4J Code Snippet Redirect the output to a file
Share My Creation [B4X Tool] - B4XIDEViewer V. 1.0
  1. Erel

    Erel Administrator Staff Member Licensed User


    This example uses a Canvas node together with a Timer to draw a moving smiley.

    The Canvas node is a special node the you can draw on. The code itself is quite simple.
    On each tick Canvas.ClearRect is called to erase the previous frame, the smiley is moved and drawn again with Canvas.DrawImage.

    In this example we also programmatically add a menu which saves the canvas drawing to a file. Note that in most cases it is easier to build the menu with the scene builder.

    The following code creates a FileChooser and saves the image to the selected file:
    Sub mnuScreenshot_Action
       Timer1.Enabled = 
    Dim fc As FileChooser
    "Image"Array As String("*.png"))
    Dim fileName As String = fc.ShowSave(MainForm)
    If fileName <> "" Then
    If fileName.ToLowerCase.EndsWith(".png") = False Then fileName = fileName & ".png"
    Dim out As OutputStream = File.OpenOutput("", fileName, False)
    Log("File saved: " & fileName)
    End If
       Timer1.Enabled = 
    End Sub
    Note that you can take snapshots of other types of nodes as well.

    Attached Files:

  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