Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: questions about a map editor

  1. #1

    questions about a map editor

    Hi. Me again,
    Since I got my sprite working, I thought I need a map editor to test my sprite on some different terrain. So I started making a little map editor for my self and I encountered a few problems:
    :arrow: How to save my tiles to array and export them to file?
    :arrow: How to make some kind of undo or deletion tool?
    Some kind of help would be much apreciated

    Best regards, leniz

  2. #2

    questions about a map editor

    :arrow: Why don't you use an already ready one?

    http://tilestudio.sourceforge.net/
    <center>
    <br />Federico &quot;FNX&quot; Nisoli
    <br />Lead Programmer - FNX Games
    <br />http://www.fnxgames.com
    <br /><img src="http://www.fnxgames.com/imgs/banners/fnxban.gif">
    <br /></center>

  3. #3

    questions about a map editor

    I tried Mappy, but it can't make the files I need. I also searched for others but none of them seem to meet my requirements. What I need is a simple map drawing utility that can save all those '0' and '1' and other chars to a simple *.txt or other file. And to tell the truth, it would be nice to work with my own made tool.

  4. #4

    questions about a map editor

    Oh, I'm making my tilemap editor too
    In my map class I use a filestream for load and save purposes. You will need to create your own file format, where you will store all map infos. A simpler approach could be using a text file to store your data.

    [pascal]
    // saving function
    var
    check, mapVer: array[0..2] of char;
    ...
    f := TFileStream.Create(filename, fmCreate);
    try
    f.Seek(0, soFromBeginning);

    check := 'emg'; // For control check when load the map
    mapVer := '001';// Version number

    F.Write(check, sizeof(check)); // I'm writing control check chars
    F.Write(mapVer, sizeof(mapVer)); // version number
    F.Write(mapName, sizeof(mapName)); // map name: string[255]
    F.Write(mapDesc, sizeof(mapDesc)); //map description: string[4000]
    F.Write(tileSet, sizeof(tileSet)); // tileset file name: string[255]
    F.Write(TileSize, SizeOf(integer)); // tile size in pixel (eg. 16): integer;
    F.Write(HorizTiles, SizeOf(integer)); //map width in tiles: integer
    F.Write(VertTiles, SizeOf(integer)); //map height in tiles: integer
    F.Write(LayerCount, SizeOf(integer)); //num of layers: integer

    for a := 0 to LayerCount - 1 do
    begin
    F.Write(Layer[a].Name, SizeOf(Layer[a].name));
    for y := 0 to VertTiles - 1 do
    for x := 0 to HorizTiles - 1 do
    begin
    F.Write(Layer[a].Tiles[x, y].ImgIndex, SizeOf(integer));
    F.Write(Layer[a].Tiles[x, y].collision, SizeOf(integer));
    end;
    end;
    f.Seek(0, soFromEnd);
    Result := true;
    finally
    f.Free;
    end;
    ...

    // Loading
    f := TFileStream.Create(filename, fmOpenRead);
    try
    f.Read(check, SizeOf(check));
    if check <> 'emg' then
    begin
    MessageDlg('Invalid .emg file.', mtError, [mbOK], 0);
    exit;
    end;

    f.Read(mapVer, SizeOf(mapVer));
    f.Read(mapName, sizeof(mapName));
    f.Read(mapDesc, sizeof(mapDesc));
    f.Read(tileSet, sizeof(tileSet));
    f.Read(TileSize, SizeOf(integer));
    f.Read(HorizTiles, SizeOf(integer));
    f.Read(VertTiles, SizeOf(integer));
    F.Read(LayerCount, SizeOf(integer));

    SetLength(Layer, LayerCount);
    for i := 0 to LayerCount - 1 do
    begin
    SetLength(Layer[i].tiles, HorizTiles, VertTiles);
    end;

    for a := 0 to LayerCount - 1 do
    begin
    f.Read(Layer[a].name, SizeOf(Layer[a].name));
    for y := 0 to VertTiles - 1 do
    for x := 0 to HorizTiles - 1 do
    begin
    f.Read(Layer[a].Tiles[x, y].ImgIndex, SizeOf(integer));
    f.Read(Layer[a].Tiles[x, y].collision, SizeOf(integer));
    end;
    end;
    f.Seek(0, soFromEnd);
    Result := true;
    finally
    f.Free;
    end;
    [/pascal]

    Well, something like that. You will need some adjustments, of course


    About undo, I have an Undo record like that:

    [pascal]
    TUndoRecord = record
    posX, posY: Integer;
    Layer: Integer;
    Tile: Integer;
    Collision: Integer;
    end;
    PUndoRecord = ^TUndoRecord;
    [/pascal]

    and a TList where I store the state of the tile I will change. In order to undo changes, all you need is to get the last item in TList, restore its values and remove it from TList.
    Hope it helps
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  5. #5
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    questions about a map editor

    You may also want to check out this thread which presents a set of objects that can be used as the basis for a tiled map... its based on the objects presented in this article which covers versioned data storage (as a means of illustrating the use of 'methodAddress').
    :: AthenaOfDelphi :: My Blog :: My Software ::

  6. #6

    questions about a map editor

    Legolas:
    Well that seems clear enough.. or not. And since you are creating the same thing, I'm eager to ask you:
    How are you drawing your tiles on the map?
    Because the longer I think, the more I understand that my way is very unversatile.

  7. #7

    questions about a map editor

    Quote Originally Posted by leniz
    Legolas:
    Well that seems clear enough.. or not. And since you are creating the same thing, I'm eager to ask you:
    How are you drawing your tiles on the map?
    Because the longer I think, the more I understand that my way is very unversatile.
    By looping from lower layer to higher, then tile by tile, of course
    If you mean what I'm using for rendering, then in my map editor I use unDelphiX and in my engine OpenGL, though in an older version I used DirectX9
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  8. #8

    questions about a map editor

    I meant when you are drawing your map with mouse in your map editor

  9. #9

    questions about a map editor

    Well, I handle onMouseDown, onMouseMove and onMouseUp events (in my case on a DXDraw component). It's matter of converting pixel based coordinates to map based coordinates, then write to the map the index of your selected tile (in my case there is a DXImageList with all tiles). For example:

    [pascal]
    procedure TForm1.DXDraw1MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: integer);
    var
    TileX, TileY: integer;
    begin
    TileX := X div (myMap.TileSize);
    TileY := Y div (myMap.TileSize);
    if button = mbLeft then
    // curlayer is the index of the current layer
    // TileSelected is the tile I want to draw
    begin
    // handle Undo here
    myMap.Layer[curlayer].Tiles[TileX, TileY].TileIndex := TileSelected;
    end;
    end;
    [/pascal]
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  10. #10

    questions about a map editor

    Looks similar to mine, but mine is without all that fancy 'undo' and 'curlayer' stuff
    You know, I tried to do that saving part something like yours, but all I get from the output file is a bunch (~2.7mb to be exact) of crap... I can't seem to get the hang of that array to textfile gig... Dang, being a newbie realy annoys me

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •