Learn techniques and where to get infos to use Delphi and FireMonkey for game coding. It's easy : all is included in the free Community Edition for individuals and of course in paid editions for professionals.
The replay of this webinar is available at https://serialstreameur.fr/delphicon-2021-fmx-game-engine.php
This webinar is also available in french at https://serialstreameur.fr/webinaire-20211211.php
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
Using FireMonkey as a game engine
1. Sponsored by
Using FireMonkey as a game engine
Patrick Prémartin
DELPHICON 2021
The Official Online Conference All About Embarcadero Delphi
delphicon.embarcadero.com
2. Sponsored by
Agenda
● What is a game engine ?
● What is FireMonkey ?
● Why using FireMonkey to code games ?
● Really ? Games in Delphi FMX ?
● Managing music and sound effects
● Managing backgrounds and scenes
● Managing user interface
● Managing sprites, animations and collisions
● What about 3D ?
● You want more ?
3. Sponsored by
Speaker
● Patrick Prémartin - MVP Embarcadero
● Freelance Delphi and web developer since 2000
(just after the bug)
● Delphi user since the beginning and before
with Borland / Turbo Pascal.
● Game coder since a little more (TO7-70 J)
4. Sponsored by
Speaker
● Patrick Prémartin - MVP Embarcadero
● Follow me on :
● GitHub : https://github.com/DeveloppeurPascal
● Itch.io : https://gamolf.itch.io
● Twitch : https://www.twitch.tv/patrickpremartin
● My blog : https://developpeur-pascal.fr
● LinkedIn : https://www.linkedin.com/in/patrickpremartin/
5. Sponsored by
What is a game engine ?
● A game engine is a library or set of components available to
create games.
● You have code, SDK and sometimes editor tools or you can use
external tools like Tiled to create your scenes and maps.
● A game engine is not a complete game making software like
you have with GameMaker Studio, AppGameKit Studio, Game
Guru, Clickteam Fusion, Unreal Engine or Unity but the code to
work with when creating games.
6. Sponsored by
What is a game engine ?
● There are a lot of game making software and game engines
coded in Pascal.
● One of the most known is Castle Game Engine available at
https://castle-engine.io/
It now has Delphi compatibility. Look at Michalis Kamburelis
DelphiCon 2021 session to know more about it.
https://delphicon.embarcadero.com/talks/castle-game-engine-
coming-to-delphi/
7. Sponsored by
What is a game engine ?
● You perhaps eared about some of this other game engines for
Delphi or Pascal developers :
○ Gorilla 3D Framework : https://www.gorilla3d.de
○ Apus Game Engine : https://github.com/Cooler2/ApusGameEngine
○ SDL2 for Pascal : https://github.com/PascalGameDevelopment/SDL2-for-
Pascal
○ Andorra 2D, Turbu, Asphyre, DelphiX, Rage3D, and a lot more listed at
https://wiki.freepascal.org/Game_Engine
8. Sponsored by
What is FireMonkey ?
● FireMonkey is the multiplatform set of components and
libraries available in Delphi.
● You have VCL for Windows projects since Delphi 1.
● And since Delphi XE2 we have FireMonkey for all major
platforms.
● With Delphi 11 Alexandria you can target Windows, Mac, Linux,
iOS and Android platforms depending on your license level.
9. Sponsored by
What is FireMonkey ?
● The idea behind FireMonkey is to have one project and one
source code to target all major platforms.
● You don’t need to know “platforms languages” like Objective-C,
Swift, Java, Kotlin, C, C++, C#, .Net, …
10. Sponsored by
What is FireMonkey ?
● FireMonkey includes classic visual components but also
shapes, animations, visual effects, 3D, access to system API
and other libraries.
● It’s included in all Delphi license level even the Community
Edition (free for personal use) and Academic Edition.
11. Sponsored by
Why using FireMonkey to code games ?
● The simple answer could be “why not ?” and in fact it’s the first
reason I had to play with it.
● Second answer is more technical :
● FireMonkey draws everything on screen by default.
● Visual components are sets of shapes and effects. They are styled and can
be changed without coding.
● We have 2D and 3D components and layers in standard.
12. Sponsored by
Why using FireMonkey to code games ?
● The simple answer could be “why not ?” and in fact it’s the first
reason I had to play with it.
● Second answer is more technical :
● Touch, mouse and keyboard are managed by Delphi. It works for classic
programs, so it works for games too.
● We can use properties and events, timers and threads, multi resolution
images and bitmaps, classes and all thinks needed to code games.
13. Sponsored by
Really ? Games in Delphi FMX ?
● In 2021 I streamed weekly game coding sessions on Twitch,
with Delphi and FireMonkey.
● Published games are available at https://gamolf.itch.io
● Some projects have been open sourced on my GitHub account:
https://github.com/DeveloppeurPascal/DevPas-Games-Pack
● A lots of other projects are available with “delphi-game”
hashtag: https://github.com/topics/delphi-game
14. Sponsored by
Really ? Games in Delphi FMX ?
● You can also check the showcase part of Embarcadero blogs at
https://blogs.embarcadero.com/category/showcase/
● And more on iOS and Android stores !
● Simply look at the list of games which developers forgot to
change default package name in their project options :
https://www.google.com/search?q=%22com.embarcadero.%22
+game+site%3Aplay.google.com
Please don’t forget to personalize your project version info option page.
15. Sponsored by
How to ?
● Know, let’s look a little more at developer side of game making
with FireMonkey projects in Delphi.
● You’ll find code samples and usable Delphi units on GitHub at
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts
16. Sponsored by
Managing music and sound effects
● Managing sounds in a Delphi project is simple. We have a
component for that : TMediaPlayer.
● In my games I use it to play MP3 music in background. A timer
check if the music is over and restart it for a loop.
● For sound effects, I play WAV files with another TMediaPlayer
(or more than one in a TObjectList<TMediaPlayer> depending
on the game).
● To do the same, use the TMusicLoop class in uMusicLoop.pas
17. Sponsored by
Managing backgrounds and scenes
● For backgrounds and scenes, I use TImage component, the Fill
property of shapes like TRectangle or TCircle and the TPath to
draw SVG path depending on my needs.
● All FireMonkey visual components are containers. They can be
parents for all other visual components.
● All visual components have opacity, rotation and scale
properties.
18. Sponsored by
Managing backgrounds and scenes
● We can use nonvisual components to change property values in
a specific duration (TFloatAnimation is very useful).
● We have visual effect as nonvisual components like
TShadowEffect and TGlowEffect, useful for games and classic
programs to show errors or needed edit fields.
● It give us unlimited possibilities without coding anything… and
of course we can code !
19. Sponsored by
Managing backgrounds and scenes
● For Egg Hunter project, available at https://gamolf.itch.io/egg-
hunter, I needed to manage sprites positions and actions in
different threads.
● I wanted 60 FPS (because we need goals in life).
● I didn’t check if I succeeded but the result is good enough in
term of user experience.
20. Sponsored by
Managing backgrounds and scenes
● My scene is a TImage. I never draw on it.
● I use a TBitmap in background as a buffer. It’s only refreshed
depending on the viewport position and sprite actions.
● A timer checks every 16ms if I changed the buffer bitmap. If so,
I copy it to the scene image.
● It’s simple. Just need some Booleans and TMutex to avoid
access violations, conflicts and sprites flipping.
21. Sponsored by
Managing backgrounds and scenes
● In other games, I simply use TLayout on a TForm to simulate a
Z-Index if needed.
● You have a sample at
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/AnimationVaguesEtCanards
● I used it for Ok Ducky ! game available at
https://gamolf.itch.io/ok-ducky
22. Sponsored by
Managing user interface
● User interface is simple : I can use styled visual components,
shapes, images, …
● For texts I user TLabel if I want the look and feel of the OS or
TText when I prefer to change color, size and font in my
program.
● For buttons I use TButton, a personalized button style or I
“draw” them in a TFrame with TRectangle, images, effects and
texts.
23. Sponsored by
Managing user interface
● Have a look at this 2018 CodeRage replay to see how I proceed :
https://serialstreameur.fr/coderage2018-christmasgame-
codereview.php
● This project source code is available on GitHub :
https://github.com/DeveloppeurPascal/CodeRage2018-
ChristmasGame
24. Sponsored by
Managing sprites, animations and collisions
● For sprites I use the bitmap kind of Fill property from
TRectangle or TCircle components.
● For other visual elements I use TImage with a TImageList or the
background (Fill.Bitmap) of other shapes.
25. Sponsored by
Managing sprites, animations and collisions
● Animating is easy : FireMonkey give us a TBitmapListAnimation
component which accepts a sprite sheet.
● Look this samples :
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/AnimSpriteExplosion
and
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/AnimSpritePersonnage
26. Sponsored by
Managing sprites, animations and collisions
● To check collisions, I use what Delphi use for the visual
components and testing mouse clicks.
● IntersectRect() is a very useful (too unknown) method to check
if two rectangles collide.
● It’s standard. It works since more than 26 years in the VCL and
now in FMX. Why not using it ?
27. Sponsored by
Managing sprites, animations and collisions
● For circles I calculate the distance between center of each circle
and compare it to the sum of their radius.
● You have a sample with Soap Bubbles game available at
https://gamolf.itch.io/soap-bubbles
● The base code for this game is available on GitHub :
https://github.com/DeveloppeurPascal/DelphiFMXGameSnippe
ts/tree/main/JeuDesCercles
28. Sponsored by
Managing sprites, animations and collisions
● For circle versus a rectangle, I calculate the distance between
the circle center and each angle of the rectangle.
● The classic sample for this is a Pong or Breakout game, when
the ball hits a wall or a brick.
● You have the source code of a sample breakout done for Learn
To Code Summer Camp 2021 event at
https://github.com/DeveloppeurPascal/Casse-Briques
29. Sponsored by
What about 3D ?
● 3D is little more complicated, but FireMonkey includes 3D
viewport and 3D shapes.
● You can use them to create games like did Grégory Bersegeay,
another French Embarcadero MVP, for
○ 3D Pong : a pong game in 3D.
https://github.com/gbegreg/FMXPong
○ FMX Corridor : a The Light Corridor remake.
https://github.com/gbegreg/FMXCorridor
○ FMX Island : an island in 3D, base for FPS games.
https://github.com/gbegreg/FMXISland
30. Sponsored by
You want more ?
● Did I say it’s simple to use Delphi and FireMonkey for game
coding and deploying them for Windows, Mac, Linux, iOS and
Android devices ?
● With those samples and links, I hope you have all what you need
to understand how to use FireMonkey as a game engine in your
games.
● If not, contact me and tell me what is missing or submit new
feature requests directly in Embarcadero’s Quality Portal.
32. Sponsored by
Q&A
● Sorry, I’m not live for Q&A during DelphiCon 2021 but if you
want to talk, leave me a message on LinkedIn or at
https://developpeur-pascal.fr/contact/
● You also can talk with me on Twitch during a live (game or
other) coding stream at
https://www.twitch.tv/patrickpremartin
● Please write in French or English.
Use https://www.deepl.com/translator tool to translate if
needed.