HGE:Tutorials:Particle Effects
HGE:Tutorials:Particle Effects
Particle systems
Particle effects in HGE use the hgeParticleSystem helper class. To create particle effects, you need to first use the Particle System Editor which is available in thehge\tools\particleed directory, assuming hge is the directory where you installed HGE. Run particleed.exe to start the editor. Create your desired particle in the editor, adjusting the parameters as necessary.
For a more complete guide to the particle system editor, see HGE Particle System Editor
The particle editor automatically saves the particles you created. Obtain this saved particle by looking in the particleed directory and retrieving a file named particleX.psi, where X is the number of the particle you modified (this number is shown beneath the "Presets & Stuff"section in the lower-right).
This .psi file is the particle description file, which will be referred to later on.
Files:HGE_warn.gif Note For this tutorial, be sure that you create a particle with a limited lifetime, not a continuous lifetime particle. In other words, the particle must disappear on its own after a specified duration. The "continuous"box in the upper-left corner should notbe checked.
Defining particles in the resource manager
Here is a sample particle description file you can use for this tutorial, or you can use your own: Media:HGE_particle.psi
Make sure to place it in the current directory and name it particle.psi
To define a particle effect, give it a name and specify the following parameters:
filename: The name of the particle description file (.psi) for the particle.
sprite: The name of the sprite it uses.
fps: The speed of the particle in frames per second.
Files:HGE_warn.gif Caution The .psi file does NOT include the sprite that is associated with the particle! You must define a sprite separately and then specify that you want to use that sprite, by using the sprite parameter.
Add the following to the resource.res file: Particle myParticle
{
filename=particle.psi
sprite=playerSprite
fps=50.0
}
For simplicity reasons, we'll just use the player sprite as a particle.
Displaying particles
First, we need the particle's info structure. This contains the parameters we defined when we created the particle (speed, lifetime, color, etc.). Next we need to create a particle managerinstance in order to display the particles. hgeParticleManager is an HGE helper class that takes care of all your particle systems and automates their creation, updating and removing. This particle manager can handle up to 100 particles at once, any new particles won't be created if there are more than 100.
Add the following at the top of the program: #include <hgeparticle.h>
hgeParticleSystemInfo myParticle;
hgeParticleManager *particleManager;
In WinMain, below the other initializations, add: myParticle = myRes->GetParticleSystem("myParticle")->info;
particleManager= new hgeParticleManager();
This retrieves the particle's info from the resource script file and creates a new instance of a particle manager.
Make sure to delete the particle manager before WinMain returns: delete particleManager;
What we will do for this tutorial is simple: Spawn a particle wherever the user clicks (in addition to the sound effect being played).
Go to the FrameFunc and make sure the statement where we played the sound now looks like this: //when left mouse is clicked, play sound effect and spawn particle
if(hge->Input_GetKey()==HGEK_LBUTTON){
chan[1] = hge->Effect_Play(mySound);
}
Below the chan[1] statement, add the following: particleManager->SpawnPS(&myParticle, mouseX, mouseY);
This will spawn a particle effect when the user clicks the left mouse button. The SpawnPS() member function takes in 3 parameters: the address of the particle's info, and the X and Y coordinates of the desired location.
Two more statements must be added in order for the particle to be displayed properly. The particle must be properly updated, just like we did for animations. It also has to be rendered, between the Gfx_BeginScene() and Gfx_EndScene() pairs.
Add the Update() function below the animation's update function, in FrameFunc: particleManager->Update(dt); //update all particles
Add the Render() function below all the other Render() statements, in FrameFunc: particleManager->Render(); //render all particles
Run the program, and whenever you click, particles will be spawned!
center
You can download the source file and resource script file for this tutorial here: Tutorial 7 source, Resource script
This concludes the HGE tutorial. You may visit the official site, HGE, for in-depth information on specific functions.
PS:particle의 도구 디렉토리에 있는 10개의 particle.psi 파일, 독자 교체 가능, 효과 보기.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
콜백 함수를 Angular 하위 구성 요소에 전달
이 예제는 구성 요소에 함수를 전달하는 것과 관련하여 최근에 직면한 문제를 다룰 것입니다.
국가 목록을 제공하는 콤보 상자 또는 테이블 구성 요소.
지금까지 모든 것이 구성 요소 자체에 캡슐화되었으며 백엔드에 대한 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
Here is a sample particle description file you can use for this tutorial, or you can use your own: Media:HGE_particle.psi
Make sure to place it in the current directory and name it particle.psi
To define a particle effect, give it a name and specify the following parameters:
filename: The name of the particle description file (.psi) for the particle.
sprite: The name of the sprite it uses.
fps: The speed of the particle in frames per second.
Files:HGE_warn.gif Caution The .psi file does NOT include the sprite that is associated with the particle! You must define a sprite separately and then specify that you want to use that sprite, by using the sprite parameter.
Add the following to the resource.res file:
Particle myParticle
{
filename=particle.psi
sprite=playerSprite
fps=50.0
}
For simplicity reasons, we'll just use the player sprite as a particle.
Displaying particles
First, we need the particle's info structure. This contains the parameters we defined when we created the particle (speed, lifetime, color, etc.). Next we need to create a particle managerinstance in order to display the particles. hgeParticleManager is an HGE helper class that takes care of all your particle systems and automates their creation, updating and removing. This particle manager can handle up to 100 particles at once, any new particles won't be created if there are more than 100.
Add the following at the top of the program: #include <hgeparticle.h>
hgeParticleSystemInfo myParticle;
hgeParticleManager *particleManager;
In WinMain, below the other initializations, add: myParticle = myRes->GetParticleSystem("myParticle")->info;
particleManager= new hgeParticleManager();
This retrieves the particle's info from the resource script file and creates a new instance of a particle manager.
Make sure to delete the particle manager before WinMain returns: delete particleManager;
What we will do for this tutorial is simple: Spawn a particle wherever the user clicks (in addition to the sound effect being played).
Go to the FrameFunc and make sure the statement where we played the sound now looks like this: //when left mouse is clicked, play sound effect and spawn particle
if(hge->Input_GetKey()==HGEK_LBUTTON){
chan[1] = hge->Effect_Play(mySound);
}
Below the chan[1] statement, add the following: particleManager->SpawnPS(&myParticle, mouseX, mouseY);
This will spawn a particle effect when the user clicks the left mouse button. The SpawnPS() member function takes in 3 parameters: the address of the particle's info, and the X and Y coordinates of the desired location.
Two more statements must be added in order for the particle to be displayed properly. The particle must be properly updated, just like we did for animations. It also has to be rendered, between the Gfx_BeginScene() and Gfx_EndScene() pairs.
Add the Update() function below the animation's update function, in FrameFunc: particleManager->Update(dt); //update all particles
Add the Render() function below all the other Render() statements, in FrameFunc: particleManager->Render(); //render all particles
Run the program, and whenever you click, particles will be spawned!
center
You can download the source file and resource script file for this tutorial here: Tutorial 7 source, Resource script
This concludes the HGE tutorial. You may visit the official site, HGE, for in-depth information on specific functions.
PS:particle의 도구 디렉토리에 있는 10개의 particle.psi 파일, 독자 교체 가능, 효과 보기.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
콜백 함수를 Angular 하위 구성 요소에 전달
이 예제는 구성 요소에 함수를 전달하는 것과 관련하여 최근에 직면한 문제를 다룰 것입니다.
국가 목록을 제공하는 콤보 상자 또는 테이블 구성 요소.
지금까지 모든 것이 구성 요소 자체에 캡슐화되었으며 백엔드에 대한 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
#include <hgeparticle.h>
hgeParticleSystemInfo myParticle;
hgeParticleManager *particleManager;
myParticle = myRes->GetParticleSystem("myParticle")->info;
particleManager= new hgeParticleManager();
delete particleManager;
//when left mouse is clicked, play sound effect and spawn particle
if(hge->Input_GetKey()==HGEK_LBUTTON){
chan[1] = hge->Effect_Play(mySound);
}
particleManager->SpawnPS(&myParticle, mouseX, mouseY);
particleManager->Update(dt); //update all particles
particleManager->Render(); //render all particles
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
콜백 함수를 Angular 하위 구성 요소에 전달이 예제는 구성 요소에 함수를 전달하는 것과 관련하여 최근에 직면한 문제를 다룰 것입니다. 국가 목록을 제공하는 콤보 상자 또는 테이블 구성 요소. 지금까지 모든 것이 구성 요소 자체에 캡슐화되었으며 백엔드에 대한 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.