Giter Site home page Giter Site logo

Platformer Terrain Help about joise HOT 2 CLOSED

sudoplaygames avatar sudoplaygames commented on July 16, 2024
Platformer Terrain Help

from joise.

Comments (2)

codetaylor avatar codetaylor commented on July 16, 2024

The example that I provided is derived directly from the platformer noise example on Joshua Tippetts site. I did not attempt to optimize it at all, I just ported his example to this ported lib.

Joshua says:

There are drawbacks to this method of terrain generation. Generating noise can be fairly slow. It is important to reduce the number of fractals, the octave count of the fractals you do use, and other slow operations as much as possible. Try to re-use fractals when you can, and cache every function that is called more than once. In this example, I was pretty liberal with the use of fractals, providing a separate one for each of the three terrain types. By using ScaleOffset to remap ranges and basing them all on a single fractal, I could have saved myself a lot of processing time.

Additionally, I would not create millions of new Block objects. I would instead create chunk objects that hold a subsection of the blocks as a single dimension byte array and access it using index = x + y * chunkwidth. This would limit you to 256 unique block types (unless you added a second array of nibbles, then you'd max at 4096 block types). Assign each block type a byte ID and create a single Block object for that block type. Then if you need to look up properties of the block, use the ID stored in the chunk array as an index into your Block object list.

To split your generation into chunks you have to sample the noise differently. To sample the noise for my game, I use something similar to the following:

int chunkPosX, chunkPosY; // (0,0), (0,1), etc..
float noiseScale 1.0f/256.0f; // play with the denominator to change scale
float sx, sy, result;
for (int x = 0; x < Chunk.WIDTH; x++) {
  for (int y = 0; y < Chunk.HEIGHT; y++) {
    sx = (x + chunkPosX * Chunk.WIDTH) * noiseScale;
    sy = (y + chunkPosY * Chunk.HEIGHT) * noiseScale;
    result = gen.get(sx,sy);
    ... // do something with result here
  }
}

Just some ideas, hope it helps!

from joise.

 avatar commented on July 16, 2024

Ok thanks!

from joise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.