particlesystem.java

来自「这是有关J2ME 3D编程的源程序」· Java 代码 · 共 57 行

JAVA
57
字号
import javax.microedition.m3g.Graphics3D;

/**
 * Manages emission of particles in our 3D world
 */
public class ParticleSystem
{
    // The effect
    private ParticleEffect effect = null;
    
    // The particles
    Particle[] parts = null;
    
    /**
     * Creates a particle system that emits particles according to a defined effect.
     * @param effect The effect that controls the behaviour of the particles
     * @param numParticles The number of particles to emit
     */
    public ParticleSystem(ParticleEffect effect, int numParticles)
    {
        // Copy the effect
        setEffect(effect);
        
        // Init the particles
        parts = new Particle[numParticles];
        for(int i = 0; i < numParticles; i++)
        {
            parts[i] = new Particle();
            effect.init(parts[i]);
        }
    }
    
    /** The method that does it all. Needs to be called every tick of a game loop */
    public void emit(Graphics3D g3d)
    {
        for(int i = 0; i < parts.length; i++)
        {
            getEffect().update(parts[i]);
            getEffect().render(parts[i], g3d);
        }
    }

    /**
     * @param effect The effect to set.
     */
    public void setEffect(ParticleEffect effect) {
        this.effect = effect;
    }

    /**
     * @return Returns the effect.
     */
    public ParticleEffect getEffect() {
        return effect;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?