From Clomosy Docs

No edit summary
No edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
TclGameForm is a customized game form design for Clomosy. Here you can use features such as animation and sound effects. Now, to create the form, it is necessary to define.
TclGameForm is a customized game form. Unlike the TclForm class, it has the following features:<br>


MyGameForm:TclGameForm;
* Animation
* Sound effects


Now we need to add and run the form before giving properties to the form.
Before using these features, the form must be initialized.<br>
An object of the TclGameForm class should be defined.
<pre>
var
  GameForm1:TclGameForm;
</pre>


begin
The defined object must be created using the "Create" function.<br>
  MyGameForm := TclGameForm.Create(Self);
<pre>
  ...
{
  MyGameForm.Run;
  GameForm1 = TCLGameForm.Create(Self);
End;
  GameForm1.Run;
 
}
Documents taken from url addresses are added to the form with the "AddGameAssetFromUrl" parameter. For example; such as background and animation images, sound file.<br>
</pre>


MyForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Tank.png');


<div class="alert alert-ligth border border-3 border-warning rounded-5 p-4 shadow-sm" role="alert">
<strong>NOTE : AddGameAssetFromUrl</strong><br> It is a function used to download an asset from a URL and include it in your application. This function is used to download a file (for example, an image or a sound file(.wav)) from the internet and save it to the file system of the project being used.
<div class="alert alert-warning" role="alert" data-bs-theme="light">
NOTE: To check if the image has been saved to the file, you can write Clomosy.AppFilesPath in the project to learn the file path extension. (Check the file on Windows.)
</div>
<b> Use of:</b>
<pre>
GameForm1.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Tank.png');
</pre>
After adding the images, these images can be transferred to a component (TclProImage, TclImage). The transfer method is as follows:<br>
After adding the images, these images can be transferred to a component (TclProImage, TclImage). The transfer method is as follows:<br>
<pre>
Image1.clSetImage('Tank.png'); //Image1:TclIamge
</pre>
</div>


ImgTank.clSetImage('Tank.png');
We can use animation and sound effects in TclGameForm. <br>
:<span style="color:blue">How to Animation?</span>
It is making a movie by showing animated pictures and still objects as if they are moving. This is how we make the pictures added on Clomosy animated.
You can set the animation height and width on the form. For this:<br>
MyGameForm.AnimationWidth := 75;
MyGameForm.AnimationHeight := 75;
If you want to give the number of animations:
MyGameForm.clAnimateBitmap.AnimationCount :=9;
To adjust the number of animation lines:


MyGameForm.clAnimateBitmap.AnimationRowCount:=3;


You can set the animation delay time on the form.
<h2> Animation </h2>
It is an effect created by displaying animated images and stationary objects as if they were moving. Essentially, a motion effect is created by quickly displaying a series of image or object frames.<br>


MyGameForm.clAnimateBitmap.Delay := 10;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
<strong>NOTE:</strong><br>
You can find the details of advanced animation features [[TclBitmapListAnimation|here]].
</div>


You can set the animation duration time on the form.
The features and usage are provided in the table below.<br>


MyGameForm.clAnimateBitmap.Duration := 2;
<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
|-
|AnimationWidth ||GameForm1.AnimationWidth = 75; || The width of the animation is adjusted.
|-
|AnimationHeight ||GameForm1.AnimationHeight = 75; || The height of the animation is adjusted.
|-
|AnimationCount ||GameForm1.clAnimateBitmap.AnimationCount = 9; || The number of animations is specified by the number of parts into which the visual is divided.
|-
|AnimationRowCount ||GameForm1.clAnimateBitmap.AnimationRowCount = 3; || The number of animation rows is specified by the number of rows into which the visual is divided.
|-
|Delay ||GameForm1.clAnimateBitmap.Delay = 10; || The transition time between visuals is specified.
|-
|Duration ||GameForm1.clAnimateBitmap.Duration = 2; || The animation duration is adjusted.
|-
|clAnimation ||GameForm1.clAnimation(Random() * MyGameForm.clWidth, Random() * MyGameForm.clHeight, 20, 'Explosion.png'); || It is used to activate the animation on the screen. This property takes 4 parameters. The 1st parameter specifies the x position, the 2nd parameter specifies the y position, the 3rd parameter specifies the rotation angle, and the 4th parameter represents the animation image.<br>
In the example, Random() is used to determine a random position.
|}
</div>


Now the "clAnimation" parameter is used so that we can show the animation on our screen. This parameter takes 4 values. (x_position,y_position,integer_value, animation_document)<br>


Random() is used below to set a random location.
<b>Example</b><br>
 
<pre>
MyGameForm.clAnimation(Random() * TForm(MyGameForm).ClientWidth, Random() * TForm(MyGameForm).ClientHeight, 20, 'Explosion.png');
  var  
 
'''Example:'''<br>
  '''var'''
   MyGameForm:TclGameForm;
   MyGameForm:TclGameForm;
   BtnRandomFire:TclButton;
   BtnRandomFire:TclButton;
   
   
   '''Procedure''' BtnRandomFireClick;
   void BtnRandomFireClick;
   '''var'''
   var  
     i:Integer;
     i:Integer;
   '''begin'''
   {
     MyGameForm.AnimationWidth := 75;  
     MyGameForm.AnimationWidth = 75;  
     MyGameForm.AnimationHeight := 75;
     MyGameForm.AnimationHeight = 75;
     MyGameForm.clAnimateBitmap.AnimationCount :=9;
     MyGameForm.clAnimateBitmap.AnimationCount =9;
     MyGameForm.clAnimateBitmap.AnimationRowCount:=3;
     MyGameForm.clAnimateBitmap.AnimationRowCount=3;
     MyGameForm.clAnimateBitmap.Delay := 10;  
     MyGameForm.clAnimateBitmap.Delay = 10;  
     MyGameForm.clAnimateBitmap.Duration := 2;
     MyGameForm.clAnimateBitmap.Duration = 2;
     For i:=0 to 5 do
     For (i = 0 to 5)
     Begin
     {
       MyGameForm.clAnimateBitmap.Delay := Random()*10;
       MyGameForm.clAnimateBitmap.Delay = Random()*10;
       MyGameForm.clAnimation(Random() * TForm(MyGameForm).ClientWidth, Random() * TForm(MyGameForm).ClientHeight, 20, 'Explosion.png');             
       MyGameForm.clAnimation(Random() * MyGameForm.clWidth, Random() * MyGameForm.clHeight, 20, 'Explosion.png');             
     End;
     }
   '''End;'''
   }
   
   
  '''begin'''
  {
   MyGameForm := TclGameForm.Create(Self);
   MyGameForm = TclGameForm.Create(Self);
   MyGameForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Explosion.png');
   MyGameForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Explosion.png');
    
    
   BtnRandomFire:= MyGameForm.AddNewButton(MyGameForm,'BtnRandomFire','RANDOM FIRE');
   BtnRandomFire= MyGameForm.AddNewButton(MyGameForm,'BtnRandomFire','RANDOM FIRE');
   MyGameForm.AddNewEvent(BtnRandomFire,tbeOnClick,'BtnRandomFireClick');
   MyGameForm.AddNewEvent(BtnRandomFire,tbeOnClick,'BtnRandomFireClick');
   BtnRandomFire.Align := alBottom;
   BtnRandomFire.Align = alBottom;
   
   
   MyGameForm.Run;
   MyGameForm.Run;
  '''End;'''
  }
 
</pre>
 
:<span style="color:blue">How to Sound Effect?</span>
 
You can include the sound effect in an event triggered within your applications, messages to alert, or wherever you want to use it.<br>
 
We need to add the sound that we will use in the form to our project.<br>


MyGameForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Fire.wav');
<h2> Sound Effects </h2>


Then we record the sound in a variable with the "RegisterSound" parameter.
It is used when you want to trigger an event, alert messages, or anywhere you want to use sound in your applications.<br>
To use the desired sound, it must be included in the project.<br>


SndFire := MyGameForm.RegisterSound('Fire.wav');
The features and usage are provided in the table below.<br>


To enable the sound effect to be heard, we need to activate it.
<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
|-
|RegisterSound ||SoundFile = GameForm1.RegisterSound('https://www.clomosy.com/game/assets/Fire.wav'); //soundFile:Integer;|| The audio file obtained from the URL should be saved to a variable.
|-
|SoundIsActive || GameForm1.SoundIsActive = True; || It is used to activate the sound effect.
|-
|PlayGameSound || GameForm1.PlayGameSound(SoundFile); || The sound activated on the application is made available for use.
|}
</div>


MyGameForm.SoundIsActive:=True;
<b>Example</b><br>
<pre>
var
  soundForm:TclGameForm;
  btnSound:TclButton;
  soundFile:Integer;


We have activated the sound in our application by making all the definitions. Now to run this in the project:<br>
void BtnSoundOnClick;
{
  soundForm.PlayGameSound(soundFile);
}


MyGameForm.PlayGameSound(SndFire);
{
  soundForm = TclGameForm.Create(Self);
  soundForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Fire.wav');


'''Example:'''<br>
  soundFile = soundForm.RegisterSound('Fire.wav');
'''var'''
  soundForm.SoundIsActive=True;
  MyGameForm:TclGameForm;
  BtnRandomFire:TclButton;
  SndFire:Integer;
  '''Procedure''' BtnRandomFireClick;
  '''begin'''
    MyGameForm.PlayGameSound(SndFire);
  '''End;'''
'''begin'''
  MyGameForm := TclGameForm.Create(Self);
  MyGameForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Fire.wav');
  SndFire := MyGameForm.RegisterSound('Fire.wav');
  MyGameForm.SoundIsActive:=True;
  BtnRandomFire:= MyGameForm.AddNewButton(MyGameForm,'BtnRandomFire','RANDOM FIRE');
  MyGameForm.AddNewEvent(BtnRandomFire,tbeOnClick,'BtnRandomFireClick');
  BtnRandomFire.Align := alBottom;
  MyGameForm.Run;
'''End;'''


:<span style="color:blue">Activating the Vibration Feature.</span>
  btnSound= soundForm.AddNewButton(soundForm,'btnSound','PLAY SOUND');
TclDeviceManager class is used to activate the vibration feature of the device in games.<br>
  soundForm.AddNewEvent(btnSound,tbeOnClick,'BtnSoundOnClick');
Let's define the variable first.<br>
  btnSound.Align = alBottom;
myDeviceManager:TclDeviceManager;
  soundForm.Run;
Let's create the variable defined on this class to activate it on the form.
}
myDeviceManager := TclDeviceManager.Create;
</pre>
Now we add the property "Vibrate" to our variable. This property takes a parameter. Time in milliseconds must be entered into this parameter.
myDeviceManager.Vibrate(1000);


'''Example:'''<br>
<h2> See Also </h2>
'''Var'''
* [[Virtual Keyboard]]
  MyForm:TclGameForm;
* [[TclForm]]
  DeviceMotionSensor:TClMotionSensor;
{{#seo:|title=TclGameForm in Clomosy - Clomosy Docs}}
  GameTimer:TClTimer;
{{#seo:|description=Explore TclGameForm in Clomosy for creating interactive game forms with animations, sound effects, and asset management for enhanced gaming experiences.}}
  BtnStartGame:TclButton;
  myDeviceManager:TclDeviceManager;
  durum : Boolean;
  '''Procedure''' BtnStartGameClick;
  '''begin'''
      myDeviceManager.Vibrate(1000);
  '''End;'''
 
'''Begin'''
  MyForm := TclGameForm.Create(Self);
  MyForm.SetFormColor('#CBEDD5','#f5e884',clGVertical);
  myDeviceManager := TclDeviceManager.Create;
  BtnStartGame:= MyForm.AddNewButton(MyForm,'BtnStartGame','Vibrate');
  BtnStartGame.Align := alBottom;
  BtnStartGame.Height:=100;
  BtnStartGame.StyledSettings := ssFamily;
  BtnStartGame.TextSettings.FontColor := clAlphaColor.clHexToColor('#FFFFFF');
  MyForm.AddNewEvent(BtnStartGame,tbeOnClick,'BtnStartGameClick');
  MyForm.Run;
'''End;'''

Latest revision as of 15:12, 24 December 2024

TclGameForm is a customized game form. Unlike the TclForm class, it has the following features:

  • Animation
  • Sound effects

Before using these features, the form must be initialized.
An object of the TclGameForm class should be defined.

var 
  GameForm1:TclGameForm;

The defined object must be created using the "Create" function.

{
  GameForm1 = TCLGameForm.Create(Self);
  GameForm1.Run;
}



Animation

It is an effect created by displaying animated images and stationary objects as if they were moving. Essentially, a motion effect is created by quickly displaying a series of image or object frames.

The features and usage are provided in the table below.

Feature Use of Definition
AnimationWidth GameForm1.AnimationWidth = 75; The width of the animation is adjusted.
AnimationHeight GameForm1.AnimationHeight = 75; The height of the animation is adjusted.
AnimationCount GameForm1.clAnimateBitmap.AnimationCount = 9; The number of animations is specified by the number of parts into which the visual is divided.
AnimationRowCount GameForm1.clAnimateBitmap.AnimationRowCount = 3; The number of animation rows is specified by the number of rows into which the visual is divided.
Delay GameForm1.clAnimateBitmap.Delay = 10; The transition time between visuals is specified.
Duration GameForm1.clAnimateBitmap.Duration = 2; The animation duration is adjusted.
clAnimation GameForm1.clAnimation(Random() * MyGameForm.clWidth, Random() * MyGameForm.clHeight, 20, 'Explosion.png'); It is used to activate the animation on the screen. This property takes 4 parameters. The 1st parameter specifies the x position, the 2nd parameter specifies the y position, the 3rd parameter specifies the rotation angle, and the 4th parameter represents the animation image.

In the example, Random() is used to determine a random position.


Example

 var 
   MyGameForm:TclGameForm;
   BtnRandomFire:TclButton;
 
   void BtnRandomFireClick;
   var 
     i:Integer;
   {
     MyGameForm.AnimationWidth = 75; 
     MyGameForm.AnimationHeight = 75;
     MyGameForm.clAnimateBitmap.AnimationCount =9;
     MyGameForm.clAnimateBitmap.AnimationRowCount=3;
     MyGameForm.clAnimateBitmap.Delay = 10; 
     MyGameForm.clAnimateBitmap.Duration = 2;
     For (i = 0 to 5)
     {
       MyGameForm.clAnimateBitmap.Delay = Random()*10;
       MyGameForm.clAnimation(Random() * MyGameForm.clWidth, Random() * MyGameForm.clHeight, 20, 'Explosion.png');            
     }
   }
 
 {
   MyGameForm = TclGameForm.Create(Self);
   MyGameForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Explosion.png');
  
   BtnRandomFire= MyGameForm.AddNewButton(MyGameForm,'BtnRandomFire','RANDOM FIRE');
   MyGameForm.AddNewEvent(BtnRandomFire,tbeOnClick,'BtnRandomFireClick');
   BtnRandomFire.Align = alBottom;
 
   MyGameForm.Run;
 }

Sound Effects

It is used when you want to trigger an event, alert messages, or anywhere you want to use sound in your applications.
To use the desired sound, it must be included in the project.

The features and usage are provided in the table below.

Feature Use of Definition
RegisterSound SoundFile = GameForm1.RegisterSound('https://www.clomosy.com/game/assets/Fire.wav'); //soundFile:Integer; The audio file obtained from the URL should be saved to a variable.
SoundIsActive GameForm1.SoundIsActive = True; It is used to activate the sound effect.
PlayGameSound GameForm1.PlayGameSound(SoundFile); The sound activated on the application is made available for use.

Example

var
  soundForm:TclGameForm;
  btnSound:TclButton;
  soundFile:Integer;

void BtnSoundOnClick;
{
  soundForm.PlayGameSound(soundFile);
}

{
  soundForm = TclGameForm.Create(Self);
  soundForm.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Fire.wav');

  soundFile = soundForm.RegisterSound('Fire.wav');
  soundForm.SoundIsActive=True;

  btnSound= soundForm.AddNewButton(soundForm,'btnSound','PLAY SOUND');
  soundForm.AddNewEvent(btnSound,tbeOnClick,'BtnSoundOnClick');
  btnSound.Align = alBottom;
  soundForm.Run;
}

See Also