If I have, for example, the following code in 'main' that is located in LG_Create:
B4X:
Font = FG.CreateFontWithParam( lGdx.Files.internal( "testfont.otf ), Param)
Is it working perfectly, because I can access the lGdx variable.
But what do I do in a CodeModule?
How do I get the lGdx variable into the CodeModule to use it?"
Sub Process_Globals
Private lGdx As LibGDX
End Sub
public Sub init( l As LibGDX )
lGdx = l
End Sub
public Sub something
Dim Param As lgFontGeneratorParameters
Param.Size = 20 * Density
Dim FG As lgFontGenerator
Dim Font As lgBitmapFont
Font = FG.CreateFontWithParam(lGdx.Files.internal("font/liquidcrystal.otf"), Param)
End Sub
But with error:
Error description:
Cannot access activity object from sub Process_Globals.
Error occurred on line:2
public Sub something( lGdx As LibGDX )
Dim Param As lgFontGeneratorParameters
Param.Size = 20 * Density
Dim FG As lgFontGenerator
Dim Font As lgBitmapFont
Font = FG.CreateFontWithParam(lGdx.Files.internal("font/liquidcrystal.otf"), Param)
End Sub
But then I have to pass the lgdx variable from sub to sub. I have a gfx code module with functions that are called from the whole program. It would be great if I could store the lgdx variable. Only how?
Sub Class_Globals
Private lGdx As LibGDX
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize ( plGdx As LibGDX )
lGdx = plGdx
End Sub
And in Process_Globals in main if I write "Private tt As test"
The error appears: Main - 38: Cannot access activity object from sub Process_Globals.
As you wrote, classes are the solution. However, I wrote "Private tt As test" in Process_Globals, which causes an error. As soon as I wrote it in Globals, it works.
I will have to investigate the difference between Process_Globals and Globals.
You can also try to set the libgdx object in main activity as PUBLIC. And then use
Main.lgdx…
Without to pass the object to functions.
That should work too.
So either you're right or I am. Personally, I would bet on you being right, but in my test program lgdx is not visible from the test class using "main."