From Clomosy Docs
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;
}
NOTE : AddGameAssetFromUrl
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.
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.)
Use of:
GameForm1.AddGameAssetFromUrl('https://www.clomosy.com/game/assets/Tank.png');
After adding the images, these images can be transferred to a component (TclProImage, TclImage). The transfer method is as follows:
Image1.clSetImage('Tank.png'); //Image1:TclIamge
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.
NOTE:
You can find the details of advanced animation features here.
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;
}