Tag Archives: delphi firemonkey

Full Android SDK Interface Files In Object Pascal For Firemonkey

Some APIs in the Android SDK are not fully exposed to Delphi XE5 and XE6 Firemonkey (and AppMethod) by default. The Android SDK needed Object Pascal interface files created to make it easier to access those APIs. There are three different automated solutions available to make this happen. I went ahead and used Java2pas against the entire set of android.jar files for Android 7, Android 8, Android 10, Android 12, Android 14, Android 15, Android 16, Android 17, and Android 19. Java2pas automatically created 3,412 interface files for Android 19 which is Android 4.4 Kitkat. Depending on which Android version you want to target you should use the interface files from that version of Android. I took all of the generated interface files from all of the Android SDK versions and uploaded them to Github. There is everything from android.security.KeyChain to android.speech.tts.TextToSpeech to android.nfc.NfcAdapter to android.opengl.GLES30 to android.os.Vibrator to android.provider.ContactsContract and literally thousands of more interfaces. What is awesome about all of these interfaces is that you can access all of them without having to modify the classes.dex file which you would have to do if this was a third party JAR.

Head over and check out the full set of Android SDK Object Pascal interface files on Github.

Tags: , , , , , , , , , , , , ,

Convert Delphi VCL Apps To Firemonkey Android And IOS Apps With Mida Converter

The Mida Team has released an updated version of the Mida Converter with support for Delphi XE6 Firemonkey. What Mida Converter does is take your existing VCL app and convert it to a Firemonkey app which can either be for desktop or mobile devices. There are quite a few new features in this release which look pretty useful for mobile developers building apps for Android and IOS devices. Mida Studio now supports the option to convert a VCL app to a mobile app and use either the DPF for IOS or the DPF for Android controls. What this might allow you to do might be to have one VCL codebase that you convert into Android and IOS versions that use the native components of each platform. It also might be easier to build a VCL app and then convert it to a Firemonkey app for IOS and target the DPF for IOS controls without having to build up the whole DPF IOS control setup yourself. It is also able to target the TMS iCL native components for IOS in addition to DPF. The new feature list claims it can do a total conversion from VCL to Firemonkey without having to add exceptions for specific components. It does mention however that single click conversion may not be possible with all applications because of the complexities involved. Some of the features that pertain to converting mobile apps are only in Mida Studio which is the more expensive version of this commercial utility.

Head over and read the full release notes for Mida Converter 4.2 on the Embarcadero forum. Or head directly to the Mida Converter website to purchase the utility and begin converting your VCL apps to run cross platform.

Tags: , , , , , , , , , , , , , , , ,

Ten Tips And Tricks For Building Games With Delphi XE5 And XE6 On Android And IOS

Game Loop. Using a game loop to handle game state updates is one method for architecting your game. The basic idea behind a game loop is that you have one function that executes each frame and inside of that function you handle character movements, projectile movements, enemy movements, collision detection, and pretty much every other action that needs to happen at an interval within your game. There are two different Flappy Firemonkey game loop examples with source code. The original example that I created uses a timer for the game loop and the second modified example uses a thread for the game loop function.

Sprite Animation. One method of doing fast image animation is with sprite sheets. Sprite sheets are all of the frames of an animation contained within the same image. The sprite component copies each frame from the bitmap and paints it in the same place over and over creating an animation. There is a TSprite component for Delphi Firemonkey that does this for you. Bitmaps are generally faster than vector drawing every frame on mobile devices.

Drawing & OpenGL. Most games have custom drawing of some kind. If you are looking to do any kind of custom drawing with Delphi Firemonkey there is a drawing example app available with quite a few functions implemented and there is also a native drawing API demo for IOS. If you want to do drawing using OpenGL directly and not just the Firemonkey functions Jim McKeeth has a blog post up with a roundup of using OpenGL with Delphi XE6. Lastly the Box2D physics engine for Firemonkey has extensive drawing examples using a TPaintBox.

Bitmap Caching. Whether you are moving one Firemonkey control around the screen or hundreds of controls around the screen you can probably benefit from image caching. On mobile devices moving bitmaps around is generally faster than letting Firemonkey manually draw every frame when nothing changed from the previous frame. Drawing your control once and then caching it as a bitmap for each additional draw is one method to accomplish this. There is a component called TImageCacheLayout that does this for you automatically. One other trick you might try to get faster drawing with Firemonkey is using a TRectangle instead of a TImage for a lighter bitmap control.

Collision Detection. Collision detection is the backbone game mechanic behind a lot of games. Every time two different objects intersect each other collision detection occurs. There are three different collision detection examples which include point based collision detection, rectangle based collision detection, and finally automatic collection detection with the Box2d for Firemonkey physics engine.

Physics Engine. Using a physics engine can greatly speed up game development because you don’t have to manually code things like gravity, buoyancy, and collision detection. You can also build complex objects that mimic real world functionality. There is a Firemonkey version of the Box2d physics engine with over 60 different demos to base a game off of including vehicle simulations, bridge simulations, an Arkanoid demo, and many more. There is a visual world editor for Box2d called RUBE which exports it’s world as JSON which can easily be imported into Delphi Firemonkey.

Artificial Intelligence. If you are looking for the characters in your games to have some kind of intelligent response to the players you need artificial intelligence algorithms. There are two different Delphi Firemonkey component suites that implement artificial intelligence functionality like neural networks. One component suite is called IntelligenceLab and the other is called Inference Engine from RiverSoftAVG.

Data Files. Most games use data files of some kind to either store levels, save the game state between play sessions, or even just storing settings of the player. In Delphi Firemonkey there are a lot of choices on how you can store your data. You can read and write simple text based files using TIniFile or you can use robust databases like SQLite for reading and writing blob data like images using FireDAC. If your game has some kind of online element to it you can use the TRESTClient controls for loading and saving data from a server.

Monetization. If you want to be able to monetize your games on mobile there are two different methods for doing so which are ads and in app payments. In Delphi XE5 there are some third party ad components for IOS and an AdMob component for Android. There is also a third party in app payment component for IOS. Delphi XE6 ships with AdMod and iAd components for Android and IOS in addition to an in app payment component which works for both Android and IOS.

High Score Systems. One thing that keeps players interested in a game is being able to compare their score against other player’s scores. Once a player has mastered a game a high score system can still keep them coming back again and again to see if they can beat the high score of other players. There is a Firemonkey example for saving user scores in the cloud using the Delphi XE5 TRESTClient components. There is also a PHP or ASP.NET server side high score system you can host yourself that can save and retrieve user scores from a MySQL database. Lastly on IOS you can plug into the Apple GameCenter API for storing high scores and other game data.

BONUS TIP: Third Party Libraries. You can always augment your Object Pascal development on Android and IOS by using existing third party libraries which may have been written in a lower level language. There are literally hundreds of existing third party libraries out there for you to access from Delphi Firemonkey. For Android devices you can load JAR files which contain Java libraries (.jar) and Android NDK libary files (.so). On IOS devices you can load static libraries (.a) to get access to additional functionality. For example, you could rapidly prototype with Box2d for Firemonkey and then if you need more speed you could import the Java version of Box2d or the C++ version of Box2d on Android.

Finally I have some advice for you on what kind of games you should build with Delphi XE5/XE6. Don’t try to build the next big 3D shooter or other super high frame rate games for hard core gamers because there are better tools to build those kinds of games (like Unity3D or Adobe Flash). Instead focus on casual games for mobile devices that Delphi Firemonkey can build well like dress up games, turn based games, classic adventure games, hidden object games, basic arcade games, drawing games, or board games using the camera. Delphi Firemonkey can excel at doing rapid application development for these types of games.

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , ,