Creating A Scene As You Go + Saving it

tamre

  • Posts: 5
I Have 2 Questions:

1st Question:

I am building a sandbox/rpg game that is procedurally generated with Perlin noise. Currently, it works but takes a long time to load to to how it works. So what I am trying to figure out (I can't find this online anywhere), is how would you make the scene generate ONLY what is on screen, so as you go along it generates the scene based on what is on screen. Any ideas how to do this?

Here is the extension I am using:
https://community.stencyl.com/index.php/topic,25079.0.html#:~:text=%22Perlin%20Noise%20Test.stencyl%22%20is%20a%20sample%20game%20showing,and%20might%20not%20work%20properly%20in%20earlier%20versions.


2nd Question:


If I can make the previous idea work, how would I save the entire scene (what has been loaded), then load it again?

Please answer this! Thanks!

merrak

  • *
  • Posts: 2712
You can use the following code to resize the scene, where width and height are the variables you set

Code: [Select]
// Set the scene for proper dimensions
getScene( ).sceneWidth = width * tileWidth;
getScene( ).sceneHeight = height * tileHeight;

        Engine.sceneWidth = getScene( ).sceneWidth;
        Engine.sceneHeight = getScene( ).sceneHeight;

I have an extension published to the forums that implements FAST XML parsing. I've used this extension to save/load world data like you are describing. Use the TileAPI to create layers and tiles as you need them.

tamre

  • Posts: 5
Where is the code meant to be placed? And how exactly will it work? As well as that please can you post a link to the extension.

merrak

  • *
  • Posts: 2712
Here are the tools you'll need.

The external data utilities will let you read/write your world data files.
https://community.stencyl.com/index.php/index.php?topic=35620.msg314634#msg314634

The XML extension isn't necessary unless you want an easy way to work with your data files with other programs. I recently used it to port maps between Stencyl and Tiled. If your world data is a simple table, I'd skip it. If you want to save multiple layers; multiple NPCs and their properties/stats; the states of objects; etc., then I'd suggest using XML. It'll make it far easier to debug your file handling routines.
https://community.stencyl.com/index.php/topic,48381.msg268083.html#msg268083

The code I gave you would be executed right before you load your world data. This is the general flowchart I use:

Code: [Select]
0. Game program begins
1. Load all world data (for you, this would be the default state of the world)
2. Player begins or continues a game and transitions to the first scene
3. In an 'on created' event:
    3A. Load the scene data header. This includes information regarding the size of the world.
    3B. Execute the code I provided above to set the proper scene size.
    3C. Parse all of the world data to build the required layers, tiles, actors, etc.
4+. Continue with the rest of the scene initialization process.