Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetComponentDelphiDemoFiremonkeyIOS

Build Device Tilt Control Mechanisms With A Motion Sensor In Delphi XE6 & XE7 Firemonkey On Android And IOS

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE6 XE7 Firemonkey Accelerometer Sample Code | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSA motion sensing Accelerometer demo in Delphi XE6 and XE7 Firemonkey allows you to track the tilt of your device. The component that the Accelerometer demo uses is called TMotionSensor. Different devices have different capabilities but the Android and iOS devices that I tested only reported Acceleration X, Acceleration Y, and Acceleration Z. The demo also lists Angle X, Angle Y, Angle Z, Motion, and Speed which it exposes through TMotionSensor.Sensor.AvailableProperties. You can use the X, Y, and Z numbers to build a control mechanism based on the tilt of the device. I added two different pieces of code using the accelerometer numbers to the demo. The first is basically a ball that rolls around on the screen when you tilt the device. The ball is confined within a circle so that it does not disappear off of the screen. You could change the confined space of the ball from the circle to the size of the screen and turn it into a game. The second control detects the tilt of the device and displays a circle which represents a direction (left, right, up, down). You could use this tilt direction detection to fire events within your app (like sliding components on and off the screen or controlling the placement and rotation of an object). The tricky part of the accelerometer is that you have to swap the X and Y depending on if your device is in Landscape or Portrait mode. The code should also work in Appmethod.

Download the modified accelerometer demo and implement tilt controls into your own apps.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

Leave a Reply