PDA

View Full Version : TileStudio for Lazarus



Ñuño Martínez
20-07-2010, 12:43 PM
Not sure if this is the place, so if moderators think it should be moved to another forum, do it. ;)

I'm sure a lot of you know about TileStudio (http://tilestudio.sf.net/); may be it's the best tilemap editor ever and it was developed with Delphi! Unfortunately it's Windows only and I didn't use Windows for a long time. I did try to use TS with Wine (http://www.winehq.org/) but it's exasperatedly slow, almost unusable (or it is it in my Xubuntu running in a core-duo; didn't test it in my "brand new" Debian, though). Since it's open-source I decided to port it to Lazarus. Mike Wiering didn't return the mails I sent and project seems dead, so I started by my own thinking it would be easy. But it wasn't at all.

Now I have a version that compiles and "runs", but it's still too slow and raises "SEGMENT FAULT" too often so it's still unusable. It's hard to trace: The main window has hundreds of components, each one with its own events and a plethora of cross-references (for example: drawing-tool to drawing-style selector to color selector to palette selector to tile TDrawBox to tile-list panel...), and a lot of them doesn't have descriptive names, or the name is descriptive but actually it doesn't does what it says it does... Also it isn't "modular" and it mixes concepts that I would keep in separate modules.

I think I have find why it's so slow: It has 3 Timers, one of them breaks each millisecond! :o I did changed the rate but then the program freezes and can't close it or raises a "SEGMENT FAULT" in random-like time. Actually I don't know what does it do but I think I can get it and fix it in the future.

I know how I can improve it (i.e. move a lot of those hundreds of components from the main form to some TFrame [PaletteEditor, ImageEditor, MapEditor, TileSelector, etc.] then put that new TFrame in the main form, use TActionList to group actions, etc.) but it will need a lot of time and work, and currently I haven't much of that.

Then, I'm asking if anybody has interest and may help. At the moment I don't want a "TileStudio 3.0", but port the current version. Since Wiering didn't answer my asking we should create a new project in SourceForge (I prefer SF), then plan the work. I'll be a bit busy next two months (until mid-September) so at start we'll go slowly.

Comments, offers, suggestions...

Legolas
20-07-2010, 01:40 PM
I did a similar thing a couple of years ago. It was a "quick and dirt" porting, only to see if Lazarus was able to compile it. Well, it was :) The executable suffered from tearing redrawing things though, at least on Windows. Just haven't investigated too much to resolve the problem ::)

Maybe I have something on my backup disk... If so, I'll be glad to share it ;)

Ñuño Martínez
21-07-2010, 05:30 PM
That would be nice, Legolas. :) I can compare with my port.

BTW, I was thinking and may be it's better to code it from the beginning. I mean keeping the ideas that makes TileStudio a good tool. Not sure yet.

dazappa
21-07-2010, 05:57 PM
It would be interesting to recreate the entire project, I suppose, but I already use different tools. Gimp for editing tiles, and Tiled for a map editor.

WILL
01-09-2010, 06:49 PM
Hows the big Tile Studio effort coming along?

Ñuño Martínez
18-09-2010, 06:51 PM
Hi Will. Sorry for the stand by, but I needed it.

I was playing with the code before my summer break. I can compile it and it runs before it tries to do something, then it freezes. i think the best option is to start it again from the beginning. I know, there are other map editors, but Tile Studio has some ideas I think makes it great.

BTW, I don't know when to start. I'm currently busy preparing the next release for Allegro.pas and have some things to do. If nobody else started it then I'll do it.

WILL
18-09-2010, 07:47 PM
No problem. :) I think a remake of a Tile Studio editor/loader is pretty neat. Mike Weiring did a great job with the original, but it lacked some documentation that might have helped, specifically in the loading, to myrecolection. I would just stress that ease of use would have to be the same when it comes to the interface or people will become discouraged from using it. Also what I felt missing was different default tiles in various sizes. 16x16, 32 x 32 and possibly 64 x 64 would be helpful for people to get to know the tool and experiment a bit. I can't quite recall if Tile Studio comes with default tiles.

alexione
19-09-2010, 06:25 AM
It would be interesting to try Lazarus Converter for Delphi applications. I see from svn log messages in Lazarus trunk that there has been lot of work on it recently.

Ñuño Martínez
19-09-2010, 10:26 AM
No problem. :) I think a remake of a Tile Studio editor/loader is pretty neat. Mike Weiring did a great job with the original, but it lacked some documentation that might have helped, specifically in the loading, to myrecolection. I would just stress that ease of use would have to be the same when it comes to the interface or people will become discouraged from using it. Also what I felt missing was different default tiles in various sizes. 16x16, 32 x 32 and possibly 64 x 64 would be helpful for people to get to know the tool and experiment a bit. I can't quite recall if Tile Studio comes with default tiles.
I can't remember it. I'm sure it has definition files to save projects in different formats.


It would be interesting to try Lazarus Converter for Delphi applications. I see from svn log messages in Lazarus trunk that there has been lot of work on it recently. Actually I did used Lazarus Converter. It does the conversion missing few things to fix by hand. The result compiles but just doesn't run. I shows the main window but if you click anywhere the program freezes. As I've said I've played with the source code but it was so complex (main form has hundreds of controls), has few comments, most object names are the default ones (i.e: "MenuItem10", etc.), it's hard to follow by myself.

Ñuño Martínez
21-10-2010, 09:01 AM
So here I am. I've decided to focus in a new TileStudio. I've started from zero because I'll do somethings different so I'll call it "TileStudio plus".

But I was working on the "tileset editor" part and I've realized that I would change the GUI. Instead of use a single form for everithing I might use a multi-window way, similar than Lazarus and Delphi. The idea is a "project window" (a project will group tilesets, maps and other stuff as DTS files in a single unit), a "tileset editor" window, a "tilemap editor" window and a "DTS description editor" (actually a simple text editor). This way you can see more than one tilemap at a glance, compare tilesets, etc.

What do you think?

WILL
21-10-2010, 01:03 PM
Not a bad idea. I'd just make sure that you don't have a huge window clutter. Maybe allow for some tool bar management options too? Allow users to save their tool bar layout perhaps?

Ñuño Martínez
22-10-2010, 09:02 AM
Not sure if I've understood you.

For window management I'll add a "window list" menu option as in Delphi/Lazarus. May be also a button or option to "order" them.

About save tool bar layout, actually the Lazarus' toolbar component is very "static", but I was planned to investigate a way to modify it.

I'll post news here when I have something to show.

Legolas
04-11-2010, 04:53 PM
Sorry for the delay :-[

I'm unsure if it could be of some use anymore, but for the record, I finally dusted my external HDD and this is my tile studio for lazarus (https://docs.google.com/leaf?id=0B4AmBqcUcEenYWEzNDI3YTYtMjUxMS00ZmQ1LWFmN 2EtNDIzYTA3ODcwMmVk&hl=en&authkey=CJ7BzZEB) :)

As I already said, it compiles fine and it somewhat works ::)

code_glitch
04-11-2010, 05:59 PM
erm, just read this thread for the first time, and read its 'slow' on wine. Now, although that is TRUE on wine < 1.2.x; I just finished installing and optimizing my new wine 1.3.6 which although being unfriendly to .Net and the like, I can report that an SU4100 with 4gb DDR3 ram seems to cope quite well on Ubuntu 10.10 (using an ATi Radeon HD4330). Although I can still see some slugishness and reluctance on maps larger than 500x500 with large tile sizes. The lazarus version seems to cope a lot better but my window just vanished (I guess thats a crash right?)... What version of wine were you using at the time and what core 2? I've noticed something funny: My 1.3ghz SU4100 cpu with 18 windows open at 40% max CPU runs around 60% faster than a 2.4ghz E6600; which should in theory thrash it in every benchmark. Is it just me or ar Ghz not the complete picture and the flops thing really accurate?

Sorry its a bit off topic, but if its down to wine 1.3.6 beta's optimization vs the older versions, you may not need to port it after all. And I found one thing so far: most of my apps work BETTER in wine than on windows. Funny isnt it? I have this new policy now: Get as many windows binaries as possible and benchmark them on a Turion RM-70 x2 64 2ghz with win7 ultimate x64 and wine 1.3.6 on ubuntu 10.10x64 with a SU4100 @ 1.3ghz

Isnt life ironic?

Ñuño Martínez
07-11-2010, 10:13 AM
Sorry for the delay :-[

I'm unsure if it could be of some use anymore, but for the record, I finally dusted my external HDD and this is my tile studio for lazarus (https://docs.google.com/leaf?id=0B4AmBqcUcEenYWEzNDI3YTYtMjUxMS00ZmQ1LWFmN 2EtNDIzYTA3ODcwMmVk&hl=en&authkey=CJ7BzZEB) :)

As I already said, it compiles fine and it somewhat works ::) Thanks. I've downloaded but I couldn't compile it. May be it uses Windows libraries and I'm using Xubuntu :$. BTW my Lazaus is doing estrange things lately, as say it can't find the "form.pp" file while it did open that file by itself. (?)


erm, just read this thread for the first time, and read its 'slow' on wine. Now, although that is TRUE on wine < 1.2.x; I just finished installing and optimizing my new wine 1.3.6 which although being unfriendly to .Net and the like, I can report that an SU4100 with 4gb DDR3 ram seems to cope quite well on Ubuntu 10.10 (using an ATi Radeon HD4330). Although I can still see some slugishness and reluctance on maps larger than 500x500 with large tile sizes. The lazarus version seems to cope a lot better but my window just vanished (I guess thats a crash right?)... What version of wine were you using at the time and what core 2? I've noticed something funny: My 1.3ghz SU4100 cpu with 18 windows open at 40% max CPU runs around 60% faster than a 2.4ghz E6600; which should in theory thrash it in every benchmark. Is it just me or ar Ghz not the complete picture and the flops thing really accurate? Well, I'm using Xubuntu, and Canonical's Linux isn't "the best of the best". Actually I find it's slower and less profiled than Debian itself (I'm testing Debian in my old IBM PentiumIV 1.8 Ghz without accelerated graphics and its slightly faster than my Dell CoreDuo T6400 2.0Ghz with accelerated Nvidia graphics, except OpenGL obviously).

The Wine I'm using is 1.2, as it is in Canonical's repository.


Sorry its a bit off topic, but if its down to wine 1.3.6 beta's optimization vs the older versions, you may not need to port it after all. And I found one thing so far: most of my apps work BETTER in wine than on windows. Funny isnt it? I have this new policy now: Get as many windows binaries as possible and benchmark them on a Turion RM-70 x2 64 2ghz with win7 ultimate x64 and wine 1.3.6 on ubuntu 10.10x64 with a SU4100 @ 1.3ghz

Isnt life ironic? This reminds me when I used to use OS/2. It has the ability to run Win16, Win32s and non NT Win32 applications, and applications that break my Windows 3.11 or my Windows 98/SE did work almost perfectly in my OS/2; and if they break then I didn't need to reboot OS/2. Actually I develop my first Windows applications in OS/2. THAT is ironic. :D

I think it's a constant. ;)

Ñuño Martínez
18-03-2013, 06:20 PM
I almost forgot this project. ::)

See. It's able to import tilesets:
1143
As you see, the import dialog is simpler than TileStudio's one. Also it uses Allegro.pas internally. This limits it a bit but I'm used to the API. Once everything works I see how to use a better graphics lib (i.e. Vampyre).

I'm having some issues with the PaintBoxes. When I change the width/height of tiles, the tile sample is re-rendered over the actual sample tile. Don't know why.

Ñuño Martínez
27-03-2013, 11:55 AM
Map edition is done. It doesn't edit everything I planned but does basic edition.
1146
The small black squares are a bug. I'm using next code to draw "void" tiles:

WITH ImageMap.Canvas DO
BEGIN
Brush.Color := clInactiveCaption;
Brush.Style := bsSolid;
Rectangle (TX , TY, TX + TW, TY + TH);
Pixels[TX, TY] := clBlack;
Pixels[TX + TW - 1, TY + TH - 1] := clWhite;
END;
It should draw a gray square and two points, but it draws a gray square with black border. Don't know why. :no:

[edit] Fixed. I forgot the "Pen" property. :-[

pstudio
27-03-2013, 12:43 PM
Try and set the pen.style to psClear;

Ñuño Martínez
27-03-2013, 12:46 PM
Try and set the pen.style to psClear; I've edited the message while you wrote your answer. :D

Yes, the problem was that I forgot the "Pen" property. Thanks.

Ñuño Martínez
12-04-2013, 01:18 PM
Last weekend I did fixed some bugs, added some brushes and added save and load map files in internal default format (not customizable yet). When I finished the user manual I decided that I don't like the way I planned to manage map layers and that the way that TileStudio manages map layers is much better, so I didn't released it yet because the internal file format is obsolete before to be released.

So, next milestone is to re-define that internal file format. Once I implement it I'll release version 0.1, just to allow you to test it and tell me what do you think about it.

Ñuño Martínez
17-05-2013, 09:34 AM
Just to say that the new internal file format isn't working, that's why I didn't released yet. I don't know whay I'm doing wrong. I still working on it.

Ñuño Martínez
27-05-2013, 05:15 PM
I've fixed the file format issue (I forgot to write the "end" of the tileset name, so it didn't find it when loading :-[). I did also some "invisible" stuff.

I was planned to release it as "version 0.1" but I think I will not until I add all stuff I planned (multilayer and "file format description language") or until somebody ask for it. ::)

WILL
12-09-2013, 10:44 AM
I'm glad to see this tool is still begin worked on. (even if slowly) Would the tool Tiled (http://www.mapeditor.org/) be of any inspiration?

I've been using it myself for my Game Maker Studio projects and it's pretty decent. There could be a few more features of course. I like how they included isometric as well as the normal 1:1 tile grid.

Something I'd love to see is a hex tile grid. Maybe animated tiles and of course the ever popular auto-tiles.

Would you consider making Tile Studio export to various formats? XML, match other popular tools (like Tiled), JSON and others?

Ñuño Martínez
14-09-2013, 05:03 PM
There could be a few more features of course. I like how they included isometric as well as the normal 1:1 tile grid.

Something I'd love to see is a hex tile grid. At the moment only normal 1:1 tile grid will be supported. But since the map drawer/editor is a TFrame with all functionality inside it should be easy to add isometric and hex tile grids too.


Maybe animated tiles and of course the ever popular auto-tiles. Not sure what "auto-tiles" is. Animated ones might be in the future too.


Would you consider making Tile Studio export to various formats? XML, match other popular tools (like Tiled), JSON and others? Actually this will be the strong point. The application will allow to define the output format by using a simple description language, simpler than the original TileStudio.

WILL
17-09-2013, 05:48 AM
Here is a couple articles/tutorials on auto-tiles: here (http://www.rmxp.tigerseye.uk.com/tutorial_resource3.shtml) and here (http://blog.rpgmakerweb.com/tutorials/anatomy-of-an-autotile/)

And now an interesting video on some dude making an auto-tile...


http://www.youtube.com/watch?v=bepko0zBUsM

Ñuño Martínez
18-09-2013, 11:01 AM
Thanks. Actually I planned to add it but didn't know how was called. :-[

Nice tutorials. :yes:

Ñuño Martínez
19-08-2016, 05:29 PM
There are only two undeniable truths in this universe:
Human stupidity has no limits.
I'm the less tenacious programmer ever.

Anyway, after playing with Tiled I decided to continue with this project, as I really need a simple tilemap editor (I'm still wondering why are other ones so complex >:().

But (and here is where my human stupidity is involved) I didn't found a clean copy of the project. It seems as I forgot to do a back-up of the latest barely-stable version and I had found a broken one. Broken because it has an unfinished "brush-selector" much like the original TileStudio one. So (more stupidity involved) I started to clean and fix, and I decided to wipe-out Allegro from the program. I started to use LCL's TBitmap and TPicture components. They aren't as bad as I remember. But not everything is wrong: I did some smart work with a few wrapper classes around Allegro's bitmaps so porting isn't so big pain. The bad thing is it loads BMP files only. But it's 0k now. ::)

At the moment it seems to import tiles correctly. Now I should update the tile selector.

Ñuño Martínez
26-08-2016, 11:06 AM
After playing with code, I'm stuck. There's something in TBimap, TPicture, TPaintBox and TCanvas that I don't understand. Sometimes they don't render what is supposed to. I'm tired of this so I decided to hack the Allegro.pas' demo map editor. Fortunately I can borrow some stuff from the work I did.

Carver413
27-08-2016, 07:56 PM
After playing with code, I'm stuck. There's something in TBimap, TPicture, TPaintBox and TCanvas that I don't understand. Sometimes they don't render what is supposed to. I'm tired of this so I decided to hack the Allegro.pas' demo map editor. Fortunately I can borrow some stuff from the work I did.
maybe you should try sdl2 it seem pretty easy to work with.

Ñuño Martínez
05-09-2016, 09:07 AM
maybe you should try sdl2 it seem pretty easy to work with. 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. ::)

Carver413
13-11-2016, 06:17 PM
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?

Ñuño Martínez
15-11-2016, 11:39 AM
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.

Wiering
17-03-2017, 06:05 AM
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!

Ñuño Martínez
17-03-2017, 07:11 PM
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!


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.


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. ::)


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.

SilverWarior
17-03-2017, 07:53 PM
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.

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


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.

Wiering
18-03-2017, 03:11 AM
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.



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;


http://www.pascalgamedevelopment.com/attachment.php?attachmentid=1452&stc=1


[Edit] I found a workaround by adding Bitmap.Mask() before every Draw, which is probably very inefficient, but now the maps are rendered correctly.

Ñuño Martínez
18-03-2017, 05:16 PM
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...

Akira13
19-03-2017, 05:29 PM
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:



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



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:



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:



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


to this:



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

Wiering
20-03-2017, 07:59 PM
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.

Ñuño Martínez
23-03-2017, 10:37 AM
Nice to read this.

My game engine (http://www.pascalgamedevelopment.com/showthread.php?32542-MinGRo-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).