From Clomosy Docs

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined motion sensor should be written.

TclMotionSensor; It is a component available in the Clomosy platform that allows you to read the values of the device's motion sensor.
The motion sensor detects the device's position and velocity. With this component, you can track the physical movements of the device.

Feature Use of Definition
TClMotionSensor DeviceMotionSensor1:TClMotionSensor; A variable belonging to the TClMotionSensor class is created.
AddNewSensorsMotion DeviceMotionSensor1= Form1.AddNewSensorsMotion(Form1,'DeviceMotionSensor1'); A new Sensor Motion is added to the form.
Active DeviceMotionSensor1.Active = True; Allows activation of the device's motion sensor.
GetDirectionX DeviceMotionSensor1.GetDirectionX It is the value returned when the device detects motion in the x-axis. The return value is as follows: if a movement to the right is detected, it returns 2; if a movement to the left is detected, it returns 1; and if no movement is detected, it returns 0.
GetDirectionY DeviceMotionSensor1.GetDirectionY This is the value returned when the device detects movement on the y-axis. The return value is: 2 if a downward motion is detected; returns 1 if an upward movement is detected; and returns 0 if no motion is detected.
SensorAccelerationX DeviceMotionSensor1.SensorAccelerationX This property is used to read the acceleration of the device along the x-axis. Acceleration along the x-axis indicates the device's speed-up or slow-down in a specific direction.
SensorAccelerationY DeviceMotionSensor1.SensorAccelerationY This property is used to read the acceleration of the device along the y-axis. Acceleration along the y-axis indicates the device's speed-up or slow-down in a specific direction.

Example

Var
MyForm:TclForm;
DeviceMotionSensor:TClMotionSensor;
GameTimer:TClTimer;
MotionImg : TCLImage;

void GameLoop;
Const 
  BallSpeed = 5;
{
  If (Clomosy.PlatformIsMobile)
  {
    Case DeviceMotionSensor.GetDirectionX of 
    {
      1:MotionImg.Position.X = MotionImg.Position.X - BallSpeed;//Move left
      2:MotionImg.Position.X = MotionImg.Position.X + BallSpeed;//Move right
    }
    Case DeviceMotionSensor.GetDirectionY of 
    {
      1:MotionImg.Position.Y = MotionImg.Position.Y - BallSpeed;//Move up
      2:MotionImg.Position.Y = MotionImg.Position.Y + BallSpeed;//Move down
    }
  }
}

{
MyForm = TclForm.Create(Self);
MyForm.SetFormBGImage('https://clomosy.com/demos/bg4.jpg');

MotionImg= MyForm.AddNewImage(MyForm,'MotionImg');
MotionImg.Align = alCenter;
MotionImg.Align = alNone;
MotionImg.Height = 200;
MotionImg.Width = 200;
MyForm.setImage(MotionImg,'https://clomosy.com/demos/balloon2.png');

DeviceMotionSensor = MyForm.AddNewSensorsMotion(MyForm,'DeviceMotionSensor');
DeviceMotionSensor.Active = True;

GameTimer= MyForm.AddNewTimer(MyForm,'GameTimer',1000);
GameTimer.Interval = 30;
GameTimer.Enabled = True;
MyForm.AddNewEvent(GameTimer,tbeOnTimer,'GameLoop');

MyForm.Run;
}

Output:


See Also