From Clomosy Docs
No edit summary |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 9: | Line 9: | ||
TclMotionSensor; It is a component available in the Clomosy platform that allows you to read the values of the device's motion sensor.<br> | TclMotionSensor; It is a component available in the Clomosy platform that allows you to read the values of the device's motion sensor.<br> | ||
The motion sensor detects the device's position and velocity. With this component, you can track the physical movements of the device.<br> | The motion sensor detects the device's position and velocity. With this component, you can track the physical movements of the device.<br> | ||
<div class="alert alert-warning" role="alert" data-bs-theme="light"> | |||
It is used on mobile devices. | |||
</div> | |||
<div class="table-responsive"> | <div class="table-responsive"> | ||
| Line 85: | Line 89: | ||
<h2> See Also </h2> | <h2> See Also </h2> | ||
* [[Sensor Structures]] | |||
* [[Components]] | * [[Components]] | ||
* [[Object Properties]] | * [[Object Properties]] | ||
* [[AddNewEvent]] | * [[AddNewEvent]] | ||
{{#seo:|description=A comprehensive guide to using motion sensors for interactive and dynamic app features.}} | |||
Latest revision as of 11:40, 20 December 2024
function AddNewSensorsMotion(AComponent: TCLComponent; xName: string): TclMotionSensor;
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.
It is used on mobile devices.
| 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: