Some help with speeding my game up?

  • I'm trying to make a sort of world-generator for a sidescroller, and the actual code I used is... Fine. Even it worked like I'd expect, it still seems super slow.

    drive.google.com/file/d/1jXLBpSh6AAoA_hqFqH23g6jLNJQRXj8d/view

    My problem is that I'm getting massive frame drops the more time it spends generating the world. The basic terrain and the bedrock added during the last step use roughly the same code, but the bedrock takes much longer than the terrain. Any advice whatsoever?

    Getting something that runs well isn't what I care about, just something that runs at least a little reasonably.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't think this with work with Tilemap. Large tilemap with small tiles will always be very slow if you fill it randomly. If you don't need collisions with the generated terrain, try using Drawing Canvas instead.

  • If you look at the debugger most of the time is spent in draw calls, presumably updating the tilemap buffers. 1.6 million quads is a lot to be shuffling around, and it'll be quite easy to use all your CPU time up. You may find it much faster to just update everything at once, or increase the area you generate per iteration. Although the obvious answer is to just reduce the tilemap size so your shuffling less data.

    Take a look at "procedural terrain generation" demo ( under advanced examples on the start page ) and you will see the terrain is generated in small chunks. Chunks are created lazily, and the tilemap content is switched around as the user moves by swapping chunk information in and out of a dictionary. This greatly reduces the size of your scene and the number of tiles that exist at any time. The downside of this approach is more complex generation code that relies on knowledge of neighbouring tiles is difficult ( neighbouring tiles might not be loaded ). The project has been optimised to keep a smooth framerate while reloading tilemap data and performing terrain generation, so the tiles may be larger than you would like. There's some things you can do to increase performance and allow for smaller tiles but may increase complexity and have other tradeoffs, such as:

    - using multiple tilemaps and moving them around ( updating less tiles per reload ).

    - limiting the horizontal or vertical size ( chunking can become 1 dimensional ).

    - using a transition to move between zones ( this allows you to use more of the loaded area, reduce the reload frequency and hide reload jank, but makes your game less seamless ).

    After saying all that... At the moment your only really drawing pixels, so as dop2000 says it would be faster to use the drawing canvas and pixel manipulation, but it has other downsides though.

    Another thought is that if your worried about generation time you can always generate the world ahead of time and pack it into your game as project files. Using procedural generation to create dozens of worlds, choosing the nicest and doing some editing is a pretty good technique for creating large spaces quickly. You can even create multiple ones and just randomly pick one at the start of the game.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)