B4A Library libGDX - Game Engine

sterlingy

Active Member
Licensed User
Informatix, I believe it is working now. I forgot to turn off debug mode on the last compile

Thank you SOOOOOOOOOO much.

-SterlingY
 

sterlingy

Active Member
Licensed User
Informatix. Here's something to chew on:

As the camera moves up the map, eventually the map end, and the Pacdroid moves into blackness (no background map.) Maps are always located with the lower left corner at (0,0). What I'd like to do is place another map and the end of the first one, and repeat this over and over, kind of like and endless runner type game.

Do you have any thoughts on how to achieve this?

Cheers,

SterlingY
 

Informatix

Expert
Licensed User
Informatix. Here's something to chew on:

As the camera moves up the map, eventually the map end, and the Pacdroid moves into blackness (no background map.) Maps are always located with the lower left corner at (0,0). What I'd like to do is place another map and the end of the first one, and repeat this over and over, kind of like and endless runner type game.

Do you have any thoughts on how to achieve this?
I don't know what's the best solution in this case. Usually, the platform games with a side scrolling have various landscapes so there's no need for repeated tiles. And the never-ending-scrolling techniques are for textures, not tiles. If you find something that works fine, let us know.
 

sterlingy

Active Member
Licensed User
I did find this: https://github.com/MobiDevelop/libgdx/blob/example/tests/gdx-tests/src/com/badlogic/gdx/tests/examples/RunnerExample.java

I was in the process of porting it to B4A, but I ran into some hurdles, as usual. For instance, it extends other classes, including one called "GdxTest" which I have know idea about.

Then there's this stuff, which I could find any reference to in your port of libGDX:
B4X:
import com.badlogic.gdx.maps.tiled.TiledMapTile;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.maps.tiled.TiledMapTileSet;
import com.badlogic.gdx.maps.tiled.TiledMapTileSets;
The coder of the above link wrote this to me on the libGDX forum:

Essentially that uses a TiledMap subclass that adds positioning, and a custom renderer that takes the map positioning into account when drawing the tiles. As it is intended to be an "endless runner", it reuses two map instances and swaps between them, regenerating each map "section" as it is swapped in.
Maybe your brilliant brain can figure it out.

Cheers,

SterlingY
 

Informatix

Expert
Licensed User
That looks good.

GdxTest is an abstract class with no code, so you don't need it.

com.badlogic.gdx.maps.tiled.TiledMapTile -> it's an interface, not a class (example of class using this interface: lgMapStaticTiledMapTile)
com.badlogic.gdx.maps.tiled.TiledMapTileLayer -> lgMapTiledMapLayer
com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell -> lgMapTiledMapLayerCell
com.badlogic.gdx.maps.tiled.TiledMapTileSet -> lgMapTiledMapSet
com.badlogic.gdx.maps.tiled.TiledMapTileSets -> lgMapTiledMapSets

Maybe your brilliant brain can figure it out.
:) My skull contains more mud than brain actually.
 

sterlingy

Active Member
Licensed User
Informatix, I've been trying to port the RunnerExample.java. Mostly it's not to difficult, but a few things I'm having trouble with:

I can't find OrthoCamController I assumed it would have been lgOrthoCamController

TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32)
I don't know what to do following the "=" as TextureRegion is not a variable

map1.getTileSets().addTileSet(tileset)
The closest I could get is : map1.TileSets.getTileSet. (and then there is no option for addTileSet)

super(map)
Not sure what super is, but it's probably not a libGDX thing

map.getLayers()
Am I assuming correctly that this translate to map.Layers.GetAllLayers?

I hope to have this working over the weekend. I'll share it with everyone, as it might be of some use. You could probably do this in 30 minutes, but even though I struggle, it helps me learn.

Cheers,

Sterling
 

Informatix

Expert
Licensed User
I can't find OrthoCamController I assumed it would have been lgOrthoCamController
If I remember correctly, it's some code to move the camera in the test apps. It's not a part of the lib and you can do the same thing with B4A (e.g. with the gesture detector).

TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32)
I don't know what to do following the "=" as TextureRegion is not a variable
Look at my Animation demo and my Map_Hexagonal demo. I show two ways to get arrays from a split.

map1.getTileSets().addTileSet(tileset)
The closest I could get is : map1.TileSets.getTileSet. (and then there is no option for addTileSet)
lgMapTiledMapSets (note the final s)

super(map)
Not sure what super is, but it's probably not a libGDX thing
Yes, forget. It calls the constructor of the ancestor of the class (you don't need to bother with that in general with B4A).

map.getLayers()
Am I assuming correctly that this translate to map.Layers.GetAllLayers?
No, to map.Layers. When a library is wrapped, usually the get and set are removed and the two functions become a single property in B4A.

I hope to have this working over the weekend. I'll share it with everyone, as it might be of some use.
Great.

Sunday, I take the plane to La Réunion island for the Christmas holidays so I won't be able to help before 2014.
 

sterlingy

Active Member
Licensed User
Thanks Informatix. Everything above is a great help. If we don't connect before, have a wonderful Christmas and New Years

Cheers,

Sterling
 

Beja

Expert
Licensed User
Thanks Informatix for the great lib and examples..

I go this error message in ALL of the examples:
Parsing code. 0.00
Compiling code. 0.03
Compiling layouts code. 0.00
Generating R file. Error
AndroidManifest.xml:17: error: No resource identifier found for attribute 'hardwareAccelerated' in package 'android'
 

sterlingy

Active Member
Licensed User
Informatix,

I finished porting the runnerExample.Java code. I can't run it yet because there are a few things I still can't find:

For starters, this is suppose to be an extension BatchSpriteMapRenderer, So I think I've not set up my globals and initialized properly

'Class module
Sub Class_Globals
Dim vertices(20) As Float
Dim thisMap As TiledMapEx
Dim Batch As lgSpriteBatch
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(vMap As TiledMapEx)

thisMap = vMap

End Sub

Public Sub renderObject(vObject As lgMapObject) '#1 this doesn't seem to be used but it was in the original code
End Sub

Public Sub renderTileLayer(vlayer As lgMapTiledMapLayer)

Dim rendMap As TiledMapEx = (TiledMapEx) getMap() '#2 I don't know what to make of this Java code. I assume that it gets a map bu treats it like the class of TiledMapEx instead of TileMap. I don't know how to change an object's class if that is the case, an what map is it getting? I assume it's something.Map or something.getMap

Dim Color As Float = Color.toFloatBits(1, 1, 1, vlayer.getOpacity) '#3 I know there is an lgCOlor, but it doesn't have "toFloatBits" as a method

Dim layerWidth As Int = vlayer.Width
Dim layerHeight As Int = vlayer.Height

Dim layerTileWidth As Float = vlayer.TileWidth * unitScale '#4 I know this should be renderer.unitScale, but the renderer is in another class. Do I need to pass it when initializing this class?
Dim layerTileHeight As Float = vlayer.TileHeight * unitScale

Dim col1 As Int = Max(0, (Int) ((viewBounds.x - rendMap.x) / layerTileWidth))
Dim col2 As Int = Min(layerWidth, (Int) (((viewBounds.x - rendMap.x) + viewBounds.width + layerTileWidth) / layerTileWidth)) '#5 Same as the unitScale issue, I guess

Dim row1 As Int = Max(0, (Int) ((viewBounds.y - rendMap.y) / layerTileHeight))
Dim row2 As Int = Min(layerHeight, (Int) (((viewBounds.y - rendMap.y) + viewBounds.height + layerTileHeight) / layerTileHeight))

Dim y As Float = row1 * layerTileHeight + rendMap.y
Dim xStart = col1 * layerTileWidth + rendMap.x
Dim vertices() As Float = this.vertices '#6 This doesn't seem to make sense to me I know b4a doesn't have "this" but also, vertices is a global array. Why's it being Dimmed again, and without the definition for the number of elements?

.
.
.
.
Dim x1 As Float = x
Dim y1 As Float = y
Dim x2 As Float = x1 + region.RegionWidth * unitScale
Dim y2 As Float = y1 + region.RegionHeight * unitScale

Dim u1 As Float = region.U
Dim v1 As Float = region.v2
Dim u2 As Float = region.u2
Dim v2 As Float = region.V

vertices(x1) = x1
vertices(y1) = y1
vertices(C1) = Color '#7 This is never declared. Perhaps there's some internal Java thing that allows it to appear out of nowhere
vertices(u1) = u1
vertices(v1) = v1

vertices(x2) = x1
vertices(y2) = y2
vertices(C2) = Color '#8 From here on down is probably the same issue as above
vertices(u2) = u1
vertices(v2) = v2

vertices(x3) = x2
vertices(y3) = y2
vertices(C3) = Color
vertices(u3) = u2
vertices(v3) = v2
Again, I hope you have or have had a great vacation. I'm in sunny California now, but will be in sub-zero temps in New England for the holidays.

-Sterlingy

P.S. I don't know why the code didn't retain it's indent formatting
 
Last edited:

Informatix

Expert
Licensed User
Thanks Informatix for the great lib and examples..

I go this error message in ALL of the examples:
In the Basic4Android IDE, go to “Tools/Configure Paths”. Be sure the android.jar is set to version 11 or higher (this setting is important to compile successfully but has no influence on the Android version required by your application, which is set in the manifest by minSdkVersion, so you can select the latest Jar present in your Android SDK folder).

"hardwareAccelerated" is not in all examples. Only a few. It is useless. You can remove the line in the manifest.
 

Informatix

Expert
Licensed User
Informatix,

I finished porting the runnerExample.Java code. I can't run it yet because there are a few things I still can't find:

For starters, this is suppose to be an extension BatchSpriteMapRenderer, So I think I've not set up my globals and initialized properly



Again, I hope you have or have had a great vacation. I'm in sunny California now, but will be in sub-zero temps in New England for the holidays.

-Sterlingy

P.S. I don't know why the code didn't retain it's indent formatting
Now that I looked closely to the code of the example, I realize that it is not easy to port to B4A (you have to extend another class, which is impossible, and not extending it complicates a lot your work). I planned for the beginning of 2014 to update my code to the version 0.9.9 of libGDX. I will provide you a solution to endlessly scroll a map at this moment. I hope you can wait a few weeks.
 

sterlingy

Active Member
Licensed User
Informatix,

I will provide you a solution to endlessly scroll a map at this moment. I hope you can wait a few weeks.
You rock. Yes, I can wait. I can work on other aspects of the mechanics, and if I run out of things to do, or just become stumped, I'll work on graphic design, plus I'll be spending a lot of time with my family anyway.

If you are wondering about functionality, It would be good to be able to load multiple maps so that one can move from one onto another, like moving from the city to the country, to the desert, then back to the city, and so forth, as opposed to one map that just repeats itself, of course, that could be an option as well.

Also, despite hours working on this, all was not in vain. I learned a lot, especially with your help.

Have a blast, and rest up while you are away, if it is possible to both!

-Sterlingy
 

Beja

Expert
Licensed User
"hardwareAccelerated" is not in all examples. Only a few.
That was a big mistake of mine, and was against my responsible of being accurate. Neutrality is
very difficult to maintain. After trying 2 examples, then I took other two randomly and it happened
they were both with "hardwareAccelerated, so I wrongly concluded it is all of the examples.

Thank you very much for the note and the help.
 

Beja

Expert
Licensed User
Informatix,

Sorry but I utterly failed to add views to the activity by creating a .bal file in designer. no errors but the
app ran normally with no button shown on the screen.. Can these examples run inside a panel?
Thanks in advance
 

Informatix

Expert
Licensed User
Informatix,

Sorry but I utterly failed to add views to the activity by creating a .bal file in designer. no errors but the
app ran normally with no button shown on the screen.. Can these examples run inside a panel?
Thanks in advance
What you're trying to do is not really clear to me. You can place a libGDX view inside a panel, of course, but you cannot add this view in your designer. It has been done programmatically.
 

sterlingy

Active Member
Licensed User
Informatix,

I hope you had a great vacation!

You'd be stunned by the progress I've made with your lib. Of course, I still struggle, but I think I'm days away from an alpha release of my app. Right now, I am stumbling over one issue.

I used the application Tiled to create a map and some polyline objects. I want to read the polylines and use their vertices to create a BOX2D edge, but I can't figure out how to access this information from the tiled map object. I can see the object layer, but not sure how to get its vertices.

Thoughts?

-S
 

Informatix

Expert
Licensed User
I hope you had a great vacation!
Yes, I left La Reunion a few days before a cyclone strikes it. I just had news from my family on the island and they are out of danger now.

You'd be stunned by the progress I've made with your lib. Of course, I still struggle, but I think I'm days away from an alpha release of my app.
Great news! I'm working too with libGDX currently.

Right now, I am stumbling over one issue. I used the application Tiled to create a map and some polyline objects. I want to read the polylines and use their vertices to create a BOX2D edge, but I can't figure out how to access this information from the tiled map object. I can see the object layer, but not sure how to get its vertices.
To be honest, I didn't test at all the lgMapPolylineMapObject class so I'm afraid that I'm of no help. I suppose that you get a polyline with one of the functions of this class and you can get its vertices with the getVertices function of the lgMathPolyline class.

I wish you (and everybody) a happy new year !
 
Top