Page 4 of 4 FirstFirst ... 234
Results 31 to 40 of 40

Thread: TileStudio for Lazarus

  1. #31
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Quote Originally Posted by Ñuño Martínez View Post
    Not sure. I feel too comfortable with Allegro. And I'm used to the new API introduced in version 5, it wasn't so hard as I initially thought. I tried SDL before and I didn't like it too much.
    there doesn't seem to be a big difference between the two. I choice Sdl 2 as it seem's the most popular. my needs are small since I work mostly with my own code. I am working on similar tools but more focus on procedural design. at the moment I am reworking the core a bit so it would be easier to adapt to other frameworks like Allegro. I had hoped that there would be a pdg game engine but it seem's the tweaker's killed any chance of that. I would have adapted my work to it. any progress in your work?

  2. #32
    Quote Originally Posted by Carver413 View Post
    any progress in your work?
    Not much. I'm pretty stuck in a "restart from the beginning" loop in almost all things I'm doing. I think I'm still ill.
    No signature provided yet.

  3. #33
    Interesting to read a thread like this...
    @Ñuño Martínez, sorry for not replying, I don't remember ever seeing your mail.

    Anyway, I've tried get Tile Studio to compile in Lazarus many times over the years and always failed, until this time.

    Now I got the tile editor working (almost) completely. The map editor however doesn't do much. There are some really strange things going on with the Canvas.Draw function with transparent bitmaps.

    It took me quite a while to figure out that the behavior of TabControl.TabIndex and Form.Resize are different from Delphi in whether events are fired or not. I don't know if such things are bugs or maybe intentional choices.

    Anyway, the newest source code is available on github: https://github.com/Wiering/Tile-Studio/tree/lazarus, maybe some of you lazarus experts immediately see what the issues are, any help would be appreciated!

  4. #34
    Quote Originally Posted by Wiering View Post
    Interesting to read a thread like this...
    @Ñuño Martínez, sorry for not replying, I don't remember ever seeing your mail.
    Don't worry. You're here now!

    Quote Originally Posted by Wiering View Post
    Anyway, I've tried get Tile Studio to compile in Lazarus many times over the years and always failed, until this time.

    Now I got the tile editor working (almost) completely. The map editor however doesn't do much. There are some really strange things going on with the Canvas.Draw function with transparent bitmaps.
    I know, I had the same problems. No idea why it doesn't work correctly.

    Quote Originally Posted by Wiering View Post
    It took me quite a while to figure out that the behavior of TabControl.TabIndex and Form.Resize are different from Delphi in whether events are fired or not. I don't know if such things are bugs or maybe intentional choices.
    I recommend to use TPageControl instead. The advantage is you don't need to "draw" the stuff by yourself tracking the tab changes. The bad thing is that it may need more memory but I think it is not your case.

    Quote Originally Posted by Wiering View Post
    Anyway, the newest source code is available on github: https://github.com/Wiering/Tile-Studio/tree/lazarus, maybe some of you lazarus experts immediately see what the issues are, any help would be appreciated!
    Ok, I've look at the GitHub project and I have to say something:

    Use subdirectories! Please. "src" for sources and "bin" for the final binary. And "docs" for documentation. Really, it will help a lot.

    The main problem I had when I worked with your code is that most of it is in the main form. That mean thousand controls and it's hard to keep track of they all. You should split the stuff, using TFrame for different control groups (i.e. I did a TFrame for the "brush" selector, another one for the tiles selector, etc). This will also group your code and increase the order.

    Also separate "logic" and "GUI" should help too. For example, split the "tile selector" in two units, one for the logic (i.e. add, remove, replace, load, save...) and the other will be the GUI that just renders the tiles and allows the user to select one of them.
    No signature provided yet.

  5. #35
    Quote Originally Posted by Wiering View Post
    There are some really strange things going on with the Canvas.Draw function with transparent bitmaps.
    Quote Originally Posted by Ñuño Martínez View Post
    I know, I had the same problems. No idea why it doesn't work correctly.
    Can you guys provide some more information about this so together we might try to figure this out.

    Quote Originally Posted by Ñuño Martínez View Post
    Also separate "logic" and "GUI" should help too. For example, split the "tile selector" in two units, one for the logic (i.e. add, remove, replace, load, save...) and the other will be the GUI that just renders the tiles and allows the user to select one of them.
    Separating logic from GUI is always a good approach. Why? Because by doing so you are making first step toward multiplatform support since usually the main difference between different platforms is the way how GUI is handled. Not to mention that you might also be opening yourself an option to start moving some lengthy operation into separate threads if needed.

  6. #36
    I know the code isn't very well structured. The whole project started as a little tool for myself which I kept expanding.

    Can you guys provide some more information about this so together we might try to figure this out.

    Bitmap transparency doesn't seem to work properly in Lazarus (or very different from Delphi at least). At first I thought it didn't work at all (posted an issue here
    http://bugs.freepascal.org/view.php?id=31556 ), but now I see that it does work if you set up the transparent color first. However, once you draw the bitmap onto something else, it forgets its transparent color, but somehow does keep a mask of the transparency you had before. In Delphi, you can just set the transparent color at any time and it will draw the image accordingly. Here is a simple program that behaves differently in Lazarus and Delphi, see the result image below.


    Code:
    procedure TForm1.BitBtn1Click(Sender: TObject);
      var
        bmp1: TBitmap;
    begin
      bmp1 := TBitmap.Create();
      bmp1.Transparent := TRUE;
      bmp1.TransparentColor := clRed;
    
      bmp1.Width := 100;
      bmp1.Height := 100;
      with bmp1.Canvas do
      begin
        Brush.Color := clRed;
        FillRect(Rect(0, 0, 100, 100));
        Brush.Color := clYellow;
        FillRect(Rect(20, 20, 80, 80));
      end;
    
      Image1.Picture.Bitmap := TBitmap.Create();
      Image1.Picture.Bitmap.Width := 100;
      Image1.Picture.Bitmap.Height := 100;
      with Image1.Picture.Bitmap.Canvas do
      begin
        Brush.Color := clGreen;
        FillRect (Rect(0, 0, 100, 100));
        Draw(0, 0, bmp1);
      end;
    
      with bmp1.Canvas do
      begin
        Brush.Color := clBlue;
        FillRect(Rect(0, 0, 50, 50));
        Brush.Color := clRed;
        FillRect (Rect(50, 50, 100, 100));
      end;
    
      with Image1.Picture.Bitmap.Canvas do
      begin
        Brush.Color := clGreen;
        FillRect (Rect(0, 0, 100, 100));
        Draw(0, 0, bmp1);
      end;
    end;



    [Edit] I found a workaround by adding Bitmap.Mask() before every Draw, which is probably very inefficient, but now the maps are rendered correctly.
    Attached Images Attached Images
    Last edited by Wiering; 18-03-2017 at 10:07 AM.

  7. #37
    Quote Originally Posted by Wiering View Post

    Bitmap transparency doesn't seem to work properly in Lazarus (or very different from Delphi at least). At first I thought it didn't work at all (posted an issue here
    http://bugs.freepascal.org/view.php?id=31556 ), but now I see that it does work if you set up the transparent color first. However, once you draw the bitmap onto something else, it forgets its transparent color, but somehow does keep a mask of the transparency you had before. In Delphi, you can just set the transparent color at any time and it will draw the image accordingly.

    (...)

    [Edit] I found a workaround by adding Bitmap.Mask() before every Draw, which is probably very inefficient, but now the maps are rendered correctly.
    That may explain the erratic behaviour I had. Some times it works, some times it doesn't...
    No signature provided yet.

  8. #38
    Two big red flags I noticed in the source: the "WriteBitmapToPNGFile" and "ReadBitmapFromPNGFile" procedures in Tiles.pas. They simply won't work as written, in Lazarus. No matter what extension you provide the write procedure, it will always be saved as an actual bitmap (open something you've saved like this in IrfanView if you want to confirm, it will show a message alerting you about the wrong extension.) The read procedure will just straight-up raise an exception that says "Wrong image format." Here's refactored versions of both that work as intended for me:

    Code:
      procedure WriteBitmapToPNGFile (OutputFilename: string; Bitmap: TBitmap; TransparentColor: Integer);
      var
        APNG: TPortableNetworkGraphic;
      begin
        Bitmap.Transparent := True;
        Bitmap.TransparentColor := TransparentColor;
        APNG := TPortableNetworkGraphic.Create;
        APNG.Assign(Bitmap);
        Bitmap.Free;
        APNG.SaveToFile(OutputFilename);
        APNG.Free;
      end;
    
    
      procedure ReadBitmapFromPNGFile (InputFilename: string; Bitmap: TBitmap);
      var
        APNG: TPortableNetworkGraphic;
      begin
        APNG := TPortableNetworkGraphic.Create;
        APNG.LoadFromFile(InputFileName);
        Bitmap.Assign(APNG);
        APNG.Free;
      end;
    Also, in the main form, the end of the SaveCurrentTile1Click procedure needs to be changed from this

    Code:
    if UpperCase(ExtractFileExt (SavePictureDialog.Filename)) = '.PNG' then
    begin
      bmpTemp.TransparentColor := TRANS_COLOR;
      WriteBitmapToPngFile (SavePictureDialog.Filename, bmpTemp, TRANS_COLOR);
    end
    else
      bmpTemp.SaveToFile (SavePictureDialog.FileName);
    bmpTemp.Free;
    to this:

    Code:
    if UpperCase(ExtractFileExt (SavePictureDialog.Filename)) = '.PNG' then
    begin
      bmpTemp.TransparentColor := TRANS_COLOR;
      WriteBitmapToPngFile (SavePictureDialog.Filename, bmpTemp, TRANS_COLOR);
    end
    else
    begin
      bmpTemp.SaveToFile (SavePictureDialog.FileName);
      bmpTemp.Free;
    end;
    Otherwise it will raise an access violation whenever you attempt to save to PNG (since the WriteBitmapToPNGFile procedure also frees the Bitmap.)

    EDIT: Just noticed the WriteTileBitmap function called by TMainForm.Generate1Click has the same problem. The ending needs to be changed from this:

    Code:
        if Ext = '.PNG' then
          WriteBitmapToPngFile(Filename, TempBitmap, TransColor)
        else
          TempBitmap.SaveToFile(FileName);
      end;
      TempBitmap.Free;
      WriteTileBitmap := True;
    to this:

    Code:
        if Ext = '.PNG' then
          WriteBitmapToPngFile(Filename, TempBitmap, TransColor)
        else
        begin
          TempBitmap.SaveToFile(FileName);
          TempBitmap.Free;
        end;
      end;
      WriteTileBitmap := True;
    Last edited by Akira13; 20-03-2017 at 01:32 AM.

  9. #39
    Thanks, I hadn't noticed that it was actually saving BMP files instead of PNG. I removed Bitmap.Free to make it compatible with the rest of the code.

    I finally got the code generation to work now, at least for a simple project. It does still need to be tested a lot more to make sure all commands work properly.

  10. #40
    Nice to read this.

    My game engine has its own simple and limited map editor but once TileStudio is up and running I'll work on one or two tsd files if possible (I'm using IFF file format and need to calculate sizes in bytes).
    Last edited by Ñuño Martínez; 23-03-2017 at 10:40 AM.
    No signature provided yet.

Page 4 of 4 FirstFirst ... 234

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
  •