Game Development Reference
In-Depth Information
5. That's the influencer part. Let's make sure influenceRealtime is
called from the ParticleEmitter class. At the end of the up-
dateParticle method, add the following code:
particleInfluencer.influenceRealtime(p, tpf);
Unfortunately, we also need to comment out the following line:
//p.imageIndex = (int) (b * imagesX * imagesY);
In the last section of the recipe, we will create a control that will update the
ParticleInfluencer class. This consists of the following steps:
1. We create a new class called BirdParticleEmitterControl and make it
extend AbstractControl . The important bit here is the controlUpdate
method where we in turn call the update method of the ParticleEmitter
instance:
public void controlUpdate(float tpf){
super.update(tpf);
if(spatial != null && spatial instanceof
ParticleEmitter){
((ParticleEmitter)spatial).getParticleInfluencer().update(tpf);
}
}
2. Apart from that, we also need to add the following code for it to work properly:
public Control cloneForSpatial(Spatial spatial) {
return new BirdParticleEmitterControl();
}
3. To affect the birds by our changes, we need to do a few more things. First, we
need to open the birds scene in the SceneComposer window.
4. Selecting the Emitter element, we need to choose Add Control.. and then select
Custom Control . Our newly created control should be available in the list.
5. Now, we need to load the scene inside an application. We just load the scene and
move it up into the sky by using the following code:
Search WWH ::




Custom Search