Full-featured Sprite Sheet Editor inside Castle Game Engine, also our own castle-sprite-sheet format

Posted on

Sprite sheet editor
Sprite sheet editor
New sprite sheet menu
Sprite sheet import Starling
Sprite sheet import atlas
Sprite sheet platformer demo - title
Sprite sheet platformer demo
Sprite sheet editor
Sprite sheet editor
Sprite sheet editor

Our CGE editor now includes a full-featured sprite sheet editor. This allows to create and modify sprite sheets that can be then trivially used (loading, playing animation) through TCastleScene. The resulting sprite sheets are saved in our own format (based on Starling XML) with extension .castle-sprite-sheet.

The editor is available by menu item Data -> New Sprite Sheet (or use the context menu, just right-click on the “Files” panel). You can start by opening an existing sprite sheet, or importing an existing atlas file, or just add animation from a series of images.

The sprite sheet is comprised from a number of animations, each with its own speed (number of frames per second). You can freely create/modify/rename animations, and move images (frames) between them.

  1. A simple demo of the new approach is in examples/sprite_sheets/sprite_sheets_demo/. Note that it was done 100% visually in the editor — no extra code necessary just to load/play sprite sheet animation.

  2. Andrzej is working on a much more impressive demo in examples/platformer.

See the documentation about using sprite sheets through TCastleScene.

All of this work was done by Andrzej Kilijański — thousand thanks for getting our sprite sheet support to a whole new level!

Comments on the forum ➤

Docker image, Android upgrades, Aarch64 optimizations, FMOD on Android

Posted on

The Unholy Society

A bunch of improvements of particular interest to mobile (Android, iOS) developers. In completely related news, stay tuned for The Unholy Society on Android and iOS release 🙂

Improvements:

  1. Updated our Docker image (affects also FPC/Lazarus used to build the default CGE releases) to:

    • for FPC 3.0.2, upgrade Lazarus version to 2.0.0
    • for FPC 3.0.4, upgrade Lazarus version to 2.0.12
    • for FPC 3.2.0, upgrade Lazarus version to 2.0.12
    • for FPC trunk, upgraded SVN revisions to latest 48998 (FPC) and 64830 (Lazarus). Also documented FPC trunk support.
    • use latest Android NDK layout for libraries (to adjust to changes described here (they removed ndk-bundle/platforms/ subdirectory) and here.

    Why? We want to use latest fixes from everything 🙂 We also want GTK2 fixes from latest Lazarus 2.0.12. We also want latest FPC trunk with fix for optimizations on 64-bit ARM (Aarch64), important for mobile platforms.

  2. Updated Android and fpcupdeluxe wiki docs to reflect new locations of Android libs in Android NDK.

  3. Our Android build process was updated to use latest Android Gradle Plugin (4.1.0). Note that this also requires newer Gradle (6.5+), it will be downloaded automatically in normal setups. This fixes building with latest NDK.

  4. We now have examples/mobile/achievements/ demo. This is almost identical to the “New Project -> 2D Game” template but also reports achievements to Google Play Games or Apple Game Center.

    Old example examples/2d_dragon_spine_game/ was removed. The template “New Project -> 2D Game” now serves better to show it.

  5. Aarch64 optimizations are now enabled when FPC is >= 3.3.1 .

    Note: we just assume that if we have FPC version >= 3.3.1 then it is at least revision 48104. Documented here, see Trello ticket.

  6. FMOD service on Android works! This allows to use FMOD sound library on Android easily. By Eugene Loza and Michalis. See FMOD service on Android docs and FMOD docs.

Comments on the forum ➤

Better code navigation, new units/states creation, new ways to open source code for editing, better integration with Lazarus project

Posted on

Code menu
New TUIState dalog
New unit with class dalog
New empty unit dalog

I’ve done a number of improvements to our editor and build tool to improve the advised organization of a CGE project and allow to comfortably edit Pascal code from CGE editor.

The goal of all these changes is to make editing CGE project easier. We want to turn the combo “CGE editor + Lazarus” into something like “Unity + Visual Studio”. CGE editor can manage your project and invoke Lazarus for you to do actual editing of Pascal files. (For those of you that would prefer to use Emacs or VS Code or other editor for Pascal: this is of course coming soon too. First we just want to nail down the Lazarus experience.)

To edit the unit you have now various options:

  • In CGE editor: enter the code/ subdirectory, and double-click on a Pascal unit.

  • In CGE editor: use menu item “Code -> Edit Unit …”.

  • In CGE editor: press F12 when some design is open. This will open the associated unit.

  • In Lazarus: open the project in Lazarus, and open necessary units. All Pascal files found on the search path are automatically part of the LPI project.

Engine and editor changes:

  1. All templates and most CGE examples now put the Pascal units in code/ subdirectory. I found that it is a much better layout than keeping all Pascal files in a top-level directory (that gets “crowded” with files in larger projects).

  2. All templates come with an initial .gitignore and README.md files. You can now push your new project to GitHub / GitLab etc. quicker.

  3. New Code menu in the editor, to edit Pascal code:

    1. Open Project in Lazarus

    2. Regenerate Project (overwrites LPR, LPI, CastleAutoGenerated) (more on this below)

    3. Edit Unit… (choose unit by a dialog box)

    4. Edit Unit Associated With Design (F12, searches for unit with same basename as current design but extension .pas)

    5. New Unit (also available on popup menu when right-clicking in the “Files” panel at the bottom):

      1. Empty
      2. With Class
      3. With State (it can even automatically add the state initialization!)

    Most of the new options are rather straightforward. But 2 things listed below require following certain conventions to make them work. You may want to adjust your existing projects to follow these conventions too (nothing bad happens if you don’t, these conventions are only necessary to allow editor to perform these operations automatically; your existing games work regardless):

    1. The option “Edit Unit Associated With Design” (F12) assumes that the filenames of Pascal units and designs match. That is, for design file like xxx.castle-user-interface it just searches for Pascal unit called xxx.pas (using search paths from CastleEngineManifest.xml). This means that e.g. using it with state_main_menu.castle-user-interface design file will not automatically find gamestatemainmenu.pas unit — we recommend you to rename your state file to gamestatemainmenu.castle-user-interface.

      (We accept also .pp extension, and unit name may be lowercase or CamelCase. But lowercase is advised as more reliable on case-sensitive filesystems. This follows FPC / Lazarus.)

    2. Adding new state to the initialization requires that one of the units (listed on game_units, reachable using search paths from CastleEngineManifest.xml) has special comments:

      {$region 'Castle Initialization Uses'}
      {$endregion 'Castle Initialization Uses'}
      {$region 'Castle State Creation'}
      {$endregion 'Castle State Creation'}
      

      The first pair delimits state units declaration in the uses clause, and may look like this:

      uses SysUtils,
        CastleWindow
        {$region 'Castle Initialization Uses'}
        // The content here may be automatically updated by CGE editor.
        , GameStateMenu
        , GameStatePlay
        {$endregion 'Castle Initialization Uses'};
      

      The second pair delimits state creation lines (typically in Application.OnInitialize call) and may look like:

      {$region 'Castle State Creation'}
      // The content here may be automatically updated by CGE editor.
      StatePlay := TStatePlay.Create(Application);
      StateMenu := TStateMenu.Create(Application);
      {$endregion 'Castle State Creation'}
      

      Of course all our templates have been updated to follow these conventions. All the examples will follow shortly.

  4. “Regenerate Program” menu item (command-line: castle-engine generate-program) now generates also castleautogenerated.pas file that does some useful things:

    This avoids the need to care about them in LPR or manual gameinitialize.pas code. This way there’s less “boilerplate” in your gameinitialize.pas.

    It also allows to put in gameinitialize.pas custom command-line parsing (previously it required to modify LPR file, making it not 100% easy to autogenerate).

    Our templates and examples have been updated to follow this. You can (but don’t have to!) update your existing projects to follow this too. Just generate standalone program by “castle-engine generate-program” (and do not edit LPR or LPI or castleautogenerated.pas, to be ready to call them again). Your project will continue to build by both Lazarus and build tool (that is also why auto-generated stuff is not hidden in some temporary directory — it needs to be available for running from Lazarus).

    The LPI file now includes all Pascal files found in the CastleEngineManifest.xml search paths into the project. This makes Lazarus behavior nicer out-of-the-box, it can navigate among all units (they are all in “Project Inspector”), it looks at all Pascal source code to know when to rebuild the project.

  5. When creating a new project, we ask for Main State Name. This makes the first state name configurable for “Empty” and “3D Model Viewer” templates.

I also have some small changes to mention, too small to deserve own news post:

  1. More useful “Basic” editor tab, it is no longer disjoint from “Layout”.

  2. Initial log output is now better, with a line like Platform: Android, OS: Android, CPU: arm (32-bit).

  3. Fixed src/library/ compilation.

Comments on the forum ➤