2D Diamond (isometric) map editor - Textures extended infinitely?

前端 未结 3 1182
清歌不尽
清歌不尽 2020-12-02 00:37

I\'m currently developing a 2D isometric map editor. I display entity(cube, player) which contains points and textures. Each cubes are composed by 12 points.(12 points, but

相关标签:
3条回答
  • 2020-12-02 01:10

    Not really an answer (as the code will be rewritten anyway) so few hints for the new code instead (some of them are already mentioned in the comments).

    1. Tileset

      In the final isometric engine use sprites. They are faster and support pixel art. For my purposes I use compilation of these two free to use tilesets (64x64):

      • outside tileset
      • medieval building tileset

      Both are compatible. I compiled and edited them to suite the needs of my engine. So this is what I use (still work in progress):

      White color 0x00FFFFFF means transparent. The sprite is not enough. I added info about the height of tile and rotations.

      If you see first 4 tiles from upper left corner they all are the same thing rotated by 90 degrees. So all my tiles have index of 4 tiles (the 90 degree rotations) int rot[4]. This way I can rotate the whole map or just view. I compile the set so the rotations are next to each other. There are 3 options:

      • tile[ix].rot[]={ ix,ix,ix,ix }; where ix is tile without rotation (ground)
      • tile[ix].rot[]={ ix,ix+1,ix,ix+1 }; where ix is tile with 2 rotations (those 2 tiles with chunk of chopped tree in the middle right)
      • tile[ix].rot[]={ ix,ix+1,ix+2,ix+3 }; where ix is tile with 4 rotations (like the first tile)

      The indexes are valid of coarse only for the first tile only, the others have the whole rot[] array rotated by 1 value from neighbor. Some rotations are invisible (see the wide trees) but the tile is still present to allow rotations.

      The tile height is important for placing tiles while editing and also for automatic map generations.

      I plan to add also A* map for each tile so I can use path finding or compute watter flows and more.

    2. Map editor

      I prefer 3D maps. with bigger resolution you need to properly select the viewed area for viewing to maximize performance. Also a good idea is to create hollow underground so the rendering is much faster (this can be also done virtually during rendering process without the need of updating map).

      I recommend to code these features:

      • make ground hollow
      • make ground solid
      • random terrain (diamond & square)
      • filter out small holes and smooth edges (add the slope tiles to cubic ones)
    3. tile editor

      Apart from the obvious paint editor you should add also another features like:

      1. floor <-> ceiling
      2. left <-> right
      3. front <-> back
      4. divide large sprite into regular tiles
      5. copy/merge/paste
      6. adjust lighting after left <-> right mirror operation

      They are really handy while compiling/editing tileset resources. As you can see my tileset has many of tiles not present in the source tilesets. They were created by these functions + some minor paint editing... The colored masks on the bottom of the tileset are used to mask out and properly combine parts of tiles to create the missing ones ... (you can take one side form one tile and other from other ...)

    [Notes]

    For more info/ideas have a look at some related Q/As:

    • Improving performance of click detection on a staggered column isometric grid
    • How to procedurally generate isometric map

      And here my Standalone no install Win32 Demo:

    • demo v1.000

    • demo v1.034

    0 讨论(0)
  • 2020-12-02 01:17

    I endend by finding better way to do this code, thanks to members of stackoverflow. For people who got there by looking for a solution to a similar problem, I invite you to look at the comments for some usefull links and comment.

    0 讨论(0)
  • 2020-12-02 01:21

    In OpenGL, when you are creating a OpenGL texture manually, you can assign 4 types:

    GL_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP  and GL_CLAMP_TO_BORDER
    

    If you want to learn more from the openGL textures differences, take a look here. Basically, it extend the last pixel in a image to the rest of the reserved memory.

    In order to solve your problem, try to load the texture, modifing the parameters. I don't know if sfml allow to do it with Texture.hpp header, in the reference appear setRepeated, try to set true to see if solve the problem. Other way, loadfromfile with a size sf::IntRect(0, 0, 32, 32) in example.

    This code is not tested, but teorically, using OpenGL will work:

    void renderWindow::loadTexture(sf::String folder, int numTexture) 
    {
    
        if (mMemoryTexture.loadFromFile("textures/" + folder + "/" + to_string(numTexture) + ".jpg"))
            mTextures.push_back(mMemoryTexture);
        else
            cout << "Texture n°" << numTexture << " as failed to load." << endl;
    
        // Generate OpenGL Texture manually
        GLuint texture_handle;
        glGenTextures(1, &texture_handle);
    
        // Attach the texture
        glBindTexture(GL_TEXTURE_2D, texture_handle);
    
        // Upload to Graphic card
        glTexImage2D(
            GL_TEXTURE_2D, 0, GL_RGBA,
            mMemoryTexture.GetWidth(), mMemoryTexture.GetHeight(),
            0,
            GL_RGBA, GL_UNSIGNED_BYTE, mMemoryTexture.GetPixelsPtr()
        );
    
        // Set the values
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    }
    

    Maybe this helps you to solve your problem.

    0 讨论(0)
提交回复
热议问题