Okay, so.
-
It’s probably not a good idea to use GameLogic anymore, as I would imagine it will be deprecated at some point. Use the bge.logic module as the API uses instead.
-
Using empties to spawn the ground pieces is a bit crude, since you would have to place thousands upon thousands of empties to cover a world. It’d be easier to use Python to place the cubes at even intervals. This ties in with the next point:
-
Each cube in your example is a separate object. You can do things this way if you have a limited playfield (i.e. a small number of cubes on screen at any given time), or if you’re going for a simple level of interactivity on the ground. However, I don’t think you’ll be able to get very far before the BGE starts choking on drawing them all if you want more cubes.
You mention that you want to load up new ‘chunks’ when you get to the edge of the current one, right? I assume by ‘generate new chunks when he gets to the edges of the current one’, you mean a block of land (composed of several cubes), not to just load up more cubes when you get to the edges of one (or a row) of them, right?
If you want to go for the simple route:
I would recommend rewriting the spawn code to work with Python for simplicity to start. Otherwise, you would have to deal with spawning in empties that spawn in the cubes at specific positions in the game.
If you want to go for the more complex route:
I think it would be better to make an object that represents a whole chunk of land, rather than just spawning in several small sections (cubes) of it. I would recommend using a plane or even combining several cubes into one whole object, and then dragging the vertices of each cube in the chunk mesh up and down to form the land. To move the cube vertices evenly, you can try writing a simple function to loop through all vertices in the mesh and figure out which vertices belong to which cubes so that all vertices in a cube are moved together.
You could also try using my (somewhat buggy) Flatten module to ‘flatten’ several objects (the cube) into a single one that the BGE would use. They wouldn’t be able to be interacted with anymore without un-flattening them, but you would be able to keep the FPS relatively high. The general idea would be that you would spawn the cubes to form the world, and then flatten the cubes (or portions of them) to chunk meshes (which hold the faces for the cubes).
Basically, you would just spawn the cubes from a single script, store their references (that the scene’s addObject() function returns) into a list, and then use the Flatten function on the chunk object with the list. Something to keep in mind in the future if you need speed-ups.
Once you’re done, you should be able to recalculate the physics mesh of the object, and have the land update. This way, the BGE draws the land in actual chunks (i.e. 5x5 grid spaces), and you can easily spawn or make visible the chunks of land adjacent to the one the player is currently on. To add in a unique instance of a mesh (a chunk that you can alter), you can use the LibNew Python command. The physics mesh should be able to be updated correctly for each mesh. I recall there was a bug for this, but I’d hope it’s been fixed.
Okay, so.
If you need an example of your current spawning system in Python, just say so, and I’ll see if I can whip one up that’s pretty similar.