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 XE6 & XE7 Firemonkey Accelerometer Sample CodeA 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
DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

AndroidC++BuilderDelphiDemoFiremonkeyWindows

Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

AndroidC++BuilderCode SnippetDelphiDemoFiremonkeyIOSOSXShowcaseWindows

Powerful Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

Significant Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

Sign up for our Newsletter and
stay informed

Leave a Reply