jLibGDXemulator
Work In Progress [Open Source]
B4J vs B4A
Have you created a game in B4A using LibGDX? Wouldn't it be awesome if you could just copy-paste your code from B4A into B4J and have it work?
Well, look no further! The future is here!
Instructions:
Remember: jGameViewHelper is required to be in your libs folder.
In order to have B4J understanding the [B]Informatix[B]'s[/B][/B] B4A LibGDX syntax, I've created a sort of emulator, using [B]Erel's[/B] excellent B4J GameView lib.
Below, a B4J (left) and B4A (right) sprite animation example running side-by-side using exactly the same LibGDX code. Ok, 99% the same code...
So far, only a few basic LibGDX functions have been "ported" so don't expect any complex operations such as collision detection. This project is mainly focused in emulating the rendering part.
Remember: jGameViewHelper is required to be in your libs folder.
B4A Example:
B4J Example:
Feel free to fork or contribute to this project.
I'm looking forward to know your opinions.
Work In Progress [Open Source]
B4J vs B4A
Have you created a game in B4A using LibGDX? Wouldn't it be awesome if you could just copy-paste your code from B4A into B4J and have it work?
Well, look no further! The future is here!
Instructions:
1. Download both jLibGDXemulator and jGameViewHelper libraries and extract the files into your B4J libraries folder.
2. Include the jLibGDXemulator library in your project.
3. Add the LibGDX.bas module to your project.
2. Include the jLibGDXemulator library in your project.
3. Add the LibGDX.bas module to your project.
Remember: jGameViewHelper is required to be in your libs folder.
In order to have B4J understanding the [B]Informatix[B]'s[/B][/B] B4A LibGDX syntax, I've created a sort of emulator, using [B]Erel's[/B] excellent B4J GameView lib.
Below, a B4J (left) and B4A (right) sprite animation example running side-by-side using exactly the same LibGDX code. Ok, 99% the same code...
So far, only a few basic LibGDX functions have been "ported" so don't expect any complex operations such as collision detection. This project is mainly focused in emulating the rendering part.
Remember: jGameViewHelper is required to be in your libs folder.
B4A Example:
B4X:
'B4A Code
'=================================================
#Region Project Attributes
#ApplicationLabel: LibGDX Test
#VersionCode: 1
#VersionName: 1
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: Landscape
#CanInstallToExternalStorage: True
#End Region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: False
#End Region
'=================================================
'B4J Code
'=================================================
' #Region Project Attributes
' #MainFormWidth: 600
' #MainFormHeight: 400
' #End Region
'=================================================
Sub Process_Globals
'Common
Type Sprite(Texture As lgTexture, TextureRegion As lgTextureRegion, ActiveFrame As Int, ActiveFrameX As Int, ActiveFrameY As Int, Rows As Int, FPS As Int, TimeStamp As Long)
'B4J Code
'=================================================
' 'Standard B4J stuff
' Dim fx As JFX
' Dim MainForm As Form
'
' 'LibGDX
' Dim GLView As View
' Dim lGdx As LibGDX
' Dim Gl As lgGL
' Dim Camera As lgOrthographicCamera
' Dim Batch As lgSpriteBatch
' Dim Ryu As Sprite
'=================================================
End Sub
'B4J Code
'==========================================================
'Sub AppStart (Form1 As Form, Args() As String)
' 'MainForm Settings
' MainForm = Form1
' MainForm.SetFormStyle("UNIFIED")
' MainForm.RootPane.LoadLayout("test") 'Load the layout file.
' MainForm.Show
'
' 'Initialize the LibGDX layer
' lGdx.Initialize
'End Sub
'==========================================================
'B4A Code
'==========================================================
Sub Globals
Dim GLView As View
Dim lGdx As LibGDX
Dim Gl As lgGL
Dim Camera As lgOrthographicCamera
Dim Batch As lgSpriteBatch
Dim Ryu As Sprite
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
'Initialize the LibGDX layer
GLView = lGdx.InitializeView("LG")
Activity.AddView(GLView, 0%x, 0%y, 100%x, 100%y)
End Sub
Sub Activity_Resume
If lGdx.IsInitialized Then lGdx.Resume
End Sub
Sub Activity_Pause(UserClosed As Boolean)
If lGdx.IsInitialized Then lGdx.Pause
End Sub
'==========================================================
Sub LG_Create
'B4J Code:
' Batch.Initialize(lGdx.lgCanvas)
'B4A Code:
Batch.Initialize
'Common
Dim Texture As lgTexture
Dim TextureRegion As lgTextureRegion
Texture.Initialize("ryu.png")
TextureRegion.InitializeWithTexture(Texture)
Ryu.Texture = Texture
Ryu.TextureRegion = TextureRegion
End Sub
Sub LG_Resize(Width As Int, Height As Int)
'Sets the camera viewport
Camera.Initialize
Camera.SetToOrtho2(True, lGdx.Graphics.Width, lGdx.Graphics.Height)
End Sub
Sub LG_Render
'Clears the screen
Gl.glClear(Gl.GL10_COLOR_BUFFER_BIT)
'Updates the matrices of the camera
Camera.Update
'Uses the coordinate system specified by the camera
Batch.ProjectionMatrix = Camera.Combined
'Sprite Animator
Animation
'Renderer
Batch.Begin
Batch.DrawRegion2(Ryu.TextureRegion, 0, 0, 300, 300)
Batch.End
End Sub
Sub LG_Dispose
Batch.dispose
Ryu.Texture.dispose
End Sub
Sub LG_Pause
LG_Resume
End Sub
Sub LG_Resume
End Sub
Sub Animation
Ryu.FPS = 24
If DateTime.Now - Ryu.TimeStamp > (1 / Ryu.FPS * 1000) Then
Ryu.TimeStamp = DateTime.Now
Ryu.Rows = 8
Ryu.ActiveFrameX = Ryu.ActiveFrame Mod Ryu.Rows
Ryu.ActiveFrameY = Floor(Ryu.ActiveFrame / Ryu.Rows)
Ryu.TextureRegion.SetRegion(Ryu.ActiveFrameX * 178, _
Ryu.ActiveFrameY * 178, _
178, 178)
Ryu.TextureRegion.Flip(False, True)
Ryu.ActiveFrame = Ryu.ActiveFrame + 1
If Ryu.ActiveFrame > 9 Then Ryu.ActiveFrame = 0
End If
End Sub
B4J Example:
B4X:
'B4A Code
'=================================================
' #Region Project Attributes
' #ApplicationLabel: LibGDX Test
' #VersionCode: 1
' #VersionName: 1
' 'SupportedOrientations possible values: unspecified, landscape or portrait.
' #SupportedOrientations: Landscape
' #CanInstallToExternalStorage: True
' #End Region
'
' #Region Activity Attributes
' #FullScreen: True
' #IncludeTitle: False
' #End Region
'=================================================
'B4J Code
'=================================================
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
#End Region
'=================================================
Sub Process_Globals
'Common
Type Sprite(Texture As lgTexture, TextureRegion As lgTextureRegion, ActiveFrame As Int, ActiveFrameX As Int, ActiveFrameY As Int, Rows As Int, FPS As Int, TimeStamp As Long)
'B4J Code
'=================================================
'Standard B4J stuff
Dim fx As JFX
Dim MainForm As Form
'LibGDX
Dim GLView As View
Dim lGdx As LibGDX
Dim Gl As lgGL
Dim Camera As lgOrthographicCamera
Dim Batch As lgSpriteBatch
Dim Ryu As Sprite
'=================================================
End Sub
'B4J Code
'==========================================================
Sub AppStart (Form1 As Form, Args() As String)
'MainForm Settings
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.RootPane.LoadLayout("test") 'Load the layout file.
MainForm.Show
'Initialize the LibGDX layer
lGdx.Initialize
End Sub
'==========================================================
'B4A Code
'==========================================================
' Sub Globals
' Dim GLView As View
' Dim lGdx As LibGDX
' Dim Gl As lgGL
' Dim Camera As lgOrthographicCamera
' Dim Batch As lgSpriteBatch
' Dim Ryu As Sprite
' End Sub
'
' Sub Activity_Create(FirstTime As Boolean)
' 'Do not forget to load the layout file created with the visual designer. For example:
' Activity.LoadLayout("Layout1")
'
' 'Initialize the LibGDX layer
' GLView = lGdx.InitializeView("LG")
' Activity.AddView(GLView, 0%x, 0%y, 100%x, 100%y)
' End Sub
'
' Sub Activity_Resume
' If lGdx.IsInitialized Then lGdx.Resume
' End Sub
'
' Sub Activity_Pause(UserClosed As Boolean)
' If lGdx.IsInitialized Then lGdx.Pause
' End Sub
'==========================================================
Sub LG_Create
'B4J Code:
Batch.Initialize(lGdx.lgCanvas)
'B4A Code:
' Batch.Initialize
'Common
Dim Texture As lgTexture
Dim TextureRegion As lgTextureRegion
Texture.Initialize("ryu.png")
TextureRegion.InitializeWithTexture(Texture)
Ryu.Texture = Texture
Ryu.TextureRegion = TextureRegion
End Sub
Sub LG_Resize(Width As Int, Height As Int)
'Sets the camera viewport
Camera.Initialize
Camera.SetToOrtho2(True, lGdx.Graphics.Width, lGdx.Graphics.Height)
End Sub
Sub LG_Render
'Clears the screen
Gl.glClear(Gl.GL10_COLOR_BUFFER_BIT)
'Updates the matrices of the camera
Camera.Update
'Uses the coordinate system specified by the camera
Batch.ProjectionMatrix = Camera.Combined
'Sprite Animator
Animation
'Renderer
Batch.Begin
Batch.DrawRegion2(Ryu.TextureRegion, 0, 0, 300, 300)
Batch.End
End Sub
Sub LG_Dispose
Batch.dispose
Ryu.Texture.dispose
End Sub
Sub LG_Pause
LG_Resume
End Sub
Sub LG_Resume
End Sub
Sub Animation
Ryu.FPS = 24
If DateTime.Now - Ryu.TimeStamp > (1 / Ryu.FPS * 1000) Then
Ryu.TimeStamp = DateTime.Now
Ryu.Rows = 8
Ryu.ActiveFrameX = Ryu.ActiveFrame Mod Ryu.Rows
Ryu.ActiveFrameY = Floor(Ryu.ActiveFrame / Ryu.Rows)
Ryu.TextureRegion.SetRegion(Ryu.ActiveFrameX * 178, _
Ryu.ActiveFrameY * 178, _
178, 178)
Ryu.TextureRegion.Flip(False, True)
Ryu.ActiveFrame = Ryu.ActiveFrame + 1
If Ryu.ActiveFrame > 9 Then Ryu.ActiveFrame = 0
End If
End Sub
Feel free to fork or contribute to this project.
I'm looking forward to know your opinions.
Attachments
Last edited: