コード例 #1
0
def test_particle_burst_emission():
    effect = ParticleEffect()
    system = Particles("testSystem", 10)
    effect.add_particles(system)

    # Setup some dummy nodes, since it seems to want them
    # We might normally call "start", but that calls "enable", which
    # seems to assume that "base" exists and has physics and particle managers...
    system.setRenderParent(NodePath(PandaNode("test")))
    system.setSpawnRenderNodePath(NodePath(PandaNode("test")))
    # However, we don't want normal emission, so we now soft-stop it immediately,
    # before the system has a chance to update and emit.
    effect.softStop()

    # Now, a sanity-check: assert that we have no particles,
    # Then update the system, and assert again that we
    # have no particles. If so, then we're (hopefully)
    # not emitting normally!

    assert system.getLivingParticles() == 0
    system.update(1)
    assert system.getLivingParticles() == 0

    # Now, the real test: emit a particle-burst!
    effect.birthLitter()

    # And assert that a particle has, in fact, been emitted.
    assert system.getLivingParticles() == 1

    # Check the snake-case version, too.
    effect.birth_litter()

    assert system.getLivingParticles() == 2
コード例 #2
0
ファイル: particles.py プロジェクト: PlumpMath/spanda3D
class Explosion:
    def __init__(self, base):
        self.base = base
        self.p = Particles()
        self.p.setFactory("PointParticleFactory")
        self.p.setRenderer("LineParticleRenderer")
        self.p.setEmitter("SphereSurfaceEmitter")
        self.p.setPoolSize(256)
        self.p.setBirthRate(0.01)
        self.p.setLitterSize(256)
        self.p.setSystemLifespan(2)
        self.p.factory.setLifespanBase(5.0000)
        self.p.renderer.setTailColor(Vec4(1.0, 1.0, 0.0, 1.0))
        self.p.renderer.setHeadColor(Vec4(1.0, 0.0, 0.0, 1.0))
        self.p.renderer.setAlphaMode(BaseParticleRenderer.PRALPHAOUT)
        self.p.renderer.setUserAlpha(1.00)
        self.p.renderer.setLineScaleFactor(32.00)
        self.p.emitter.setRadius(2.0000)
        self.p.setRenderParent(base.render)
        self.p.enable()
        self.pn = base.render.attachNewNode("particleExpNode")
        # self.pn.setDepthWrite(False)
        # self.pn.setBin("fixed", 0)
        self.pe = ParticleEffect("exp-effect", self.p)
        self.pe.reparentTo(self.pn)
        self.pe.enable()