Android Example FREE Source Code's !

BarryW

Active Member
Licensed User
Longtime User

Is this available for B4A? Tnx...
 

ilan

Expert
Licensed User
Longtime User
Yes, the class should work in all b4x platforms since it is using simple b4x tools like timer or canvas that all b4x platforms have.
 

ilan

Expert
Licensed User
Longtime User
wow, more than 1,5 years since i posted a new source here. so it's time to bring this thread alive.
this is not a new source but I would like to put it here so it can be found easily and I promise that more will follow.

Catch the Fly

this is a simple game (b4x) but it shows you how you can use types and create an unlimited amount of enemies and how to perform the draw, move, hit functions.
a nice example that can be used to learn the basics of game making!

Have Fun!

 

Attachments

  • catch the fly.zip
    120.4 KB · Views: 630

ilan

Expert
Licensed User
Longtime User
A simple example of how to create a running animation (the b4x way).



B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Type kid(id As Int, x As Float, y As Float, width As Float, height As Float, moveDirection As Int, sprites(6) As B4XBitmap, frame As Int)
    Private fx As JFX
    Private MainForm As Form
    
    Private cnv As B4XCanvas
    Private kidsList As List
    Private vpW, vpH As Float
    Private myTimer As Timer
    Private frames As Int
    Private kidIndex As Int = 0
    Private xui As XUI
    Private speed As Float = 3
    Private animationSpeed As Float = 6
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    
    kidsList.Initialize
    myTimer.Initialize("myTimer",1000/60)
    cnv.Initialize(MainForm.RootPane)
    vpW = MainForm.RootPane.Width
    vpH = MainForm.RootPane.Height
    
    'create here the girls
    kidsList.Add(createGirl(vpW/2,vpH/2,0)) 'run right
'    kidsList.Add(createGirl(vpW/2,vpH/2-(vpH*0.3),1)) 'run left
'    kidsList.Add(createGirl(vpW/2,vpH/2+(vpH*0.3),1)) 'run left
    
    myTimer.Enabled = True
End Sub

Sub createGirl(x As Float, y As Float, direction As Int) As kid
    Dim girl As kid
    girl.Initialize
    girl.id = kidIndex 'uniqe id
    Dim fullsprite As B4XBitmap = xui.LoadBitmap(File.DirAssets,"spritestrip.png")
    Dim bmpwidth As Float = fullsprite.Width/girl.sprites.Length
    Dim bmpTop As Float
    If direction = 1 Then bmpTop = fullsprite.Height/2 Else bmpTop = 0
    For i = 0 To girl.sprites.Length-1
        girl.sprites(i) = fullsprite.Crop(bmpwidth*i,bmpTop,bmpwidth,fullsprite.Height/2)
    Next
    girl.width = vpW*0.2
    girl.height = girl.width
    girl.x = x-(girl.width/2)
    girl.y = y-(girl.height/2)
    girl.moveDirection = direction '0=right, 1=left
    girl.frame = 0
    kidIndex = kidIndex + 1
    Return girl
End Sub

Sub myTimer_Tick
    frames = frames+1
    clearcanvas
    moveallKids
    drawAllKids
End Sub

Sub clearcanvas
    cnv.ClearRect(cnv.TargetRect)
End Sub

Sub moveallKids
    For Each child As kid In kidsList
        If child.moveDirection = 1 Then
            child.x = child.x - speed
            If child.x < -child.width Then child.x = vpW+child.width
        Else
            child.x = child.x + speed
            If child.x > vpW Then child.x = -child.width               
        End If
    Next
End Sub

Sub drawAllKids
    For Each child As kid In kidsList
        If frames Mod animationSpeed = 0 Then child.frame = (child.frame+1) Mod child.sprites.Length
        cnv.DrawBitmap(child.sprites(child.frame),returnRect(child.x,child.y,child.width,child.height))
    Next
End Sub

Sub returnRect(x As Float, y As Float, w As Float, h As Float) As B4XRect
    Dim r As B4XRect
    r.Initialize(x,y,x+w,y+h)
    Return r
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

if you have any questions you are welcome to ask!
 

Attachments

  • spritestrip.png
    270.8 KB · Views: 564
  • SpriteAnimation.zip
    270.1 KB · Views: 560

ilan

Expert
Licensed User
Longtime User
Where is the animated gif?

there is no gif, the animation happens in the code. run the b4j app and you will get a running kid on the screen.
the code will show you how to take a sprite sheet, crop it and use it to draw animation. it is very basic for creating games.
the kid is also moving and now it is up to you to do with it something like a simple game where the kid needs to jump above an obstacle.
can you do it?
 

ilan

Expert
Licensed User
Longtime User
hi all. here is a simple example of how you could create a puzzle game where you need to drag a puzzle piece and drop it on a grid of puzzle objects.

(relevant thread)

 

Attachments

  • drag_tetris source.zip
    1.9 KB · Views: 377
  • drag_tetris.jar
    412.9 KB · Views: 354

ilan

Expert
Licensed User
Longtime User
B(x)reakout Game - Source code + YT tutorials can be found here:

 
Last edited:

ilan

Expert
Licensed User
Longtime User
Hi Guys,

i made a simple Drawing example App (b4x) with a shape selection/remove option for someone in the forum. so i will share it here.


EDIT: my drawing is horrible, sorry!
 

Attachments

  • canvas.zip
    2.9 KB · Views: 365
  • canvas.jar
    410.5 KB · Views: 292

ilan

Expert
Licensed User
Longtime User
B4XPages Transition


 

ilan

Expert
Licensed User
Longtime User
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…