Debriefing development 2D engine on WinForms
Introductory
A couple of years ago I came up with the idea of writing a
Visual Novel engine on WinForms. Why on WinForms? Because then I didn’t really know anything. Periodically, the engine has received and is receiving updates to the present day. During this time, a little useful code has accumulated that can be used everywhere.
Splitting text into lines
Sprites and PictureBox
As you know,
PictureBox has two image layers. BackgroundImage & Image. In the first versions of the engine, I used about 5 boxes to draw sprites. Such a system had several big disadvantages:
- Problems with transparency due to multi-level inheritance
- Lay out forms when updating
Later, I made the algorithm through Graphics, which made it possible to draw sprites anytime, anywhere.
PictureBox ALeft; Bitmap SpriteListPic;
LuaInterface and Try-Catch, as a feature
A little about the experience with LuaInterface:
- Supplement for an article on LuaInterface about LuaTable: For most things, you can do without functions using only tables.
lua.NewTable("Scene");
- Problems with memory leaks when working with tables
string TableReaderS(string Table, string Key) { string Ret = ""; using (LuaTable tabx = lua.GetTable(Table)) { Ret = (string)tabx[Key]; } return Ret; } int TableReaderI(string Table, string Key) { int Ret = -1; using (LuaTable tabx = lua.GetTable(Table)) { Ret = (int)(double)tabx[Key];
Each time you call GetTable , you get a new CLR object that references the Lua table referenced by this global Lua variable.
- If you are not sure what the value in the table is at all:
try { Size = TableReaderI("Scene", "Image" + Convert.ToString(num) + "Scale"); } catch (Exception ex) { Size = 2; }
Lua will return a value, but not the fact that it will be a number. Therefore Catch (Exception) . The option with double.TryParse is not suitable here, because lua.GetTable does not return a string, but a certain type, which is LuaTable and can be converted to a string if it was assigned such a value, also with a number.
Source: https://habr.com/ru/post/469599/
All Articles