如何在Corona SDK中正确使用粒子系统

时间:2016-07-02 16:47:06

标签: lua corona particle-system

所以我一直试图弄清楚如何在Corona SDK中使用粒子系统。 我已经尝试了阅读它,我已经到了发射器,但是从那里被卡住了。如何将粒子系统和发射器连接在一起?

function NewTrail()
ParticleSystem:createParticle(
    {
        flags = { "wall" },
        x = display.contentCenterX,
        y = display.contentCenterY,
        velocityX = 100,
        velocityY = 0,
        color = { 0, 0, 1, 1 },
        lifetime = 32.0
    }
)
end
timer.performWithDelay( 100, NewTrail, -1 )

-----------------------emitter---------------------------

local emitterParams = {
    textureFileName = "particle.png",
}
local emitter = display.newEmitter( emitterParams )

好的,所以在这之后没用,我想也许粒子系统和发射器是两个不同的东西所以我试过这个:

local emitterParams = {
    textureFileName = "images/particle.png",
    duration = -1,
    speed = 100,
    particleLifespan = 5,
    maxParticles = 20,
    angle = 180,
    startParticleSize = 10,
    finishParticleSize = 0,
}
local Trail = display.newEmitter( emitterParams )
Trail:start()

它仍然无效。有什么输入吗?

1 个答案:

答案 0 :(得分:0)

好的,我终于明白了。我仍然不了解发射器,所以如果有人愿意帮助你,请做。要使粒子系统工作,您必须首先启动物理学:

local physics = require( "physics" )
physics.start()

然后通过执行以下操作初始化粒子系统:

local testParticleSystem = physics.newParticleSystem(
  {
  filename = "images/particle.png",
  radius = 3,
  imageRadius = 4
  }
)

最后,您必须创建实际粒子,如下所示:

local function onTimer( event )

    testParticleSystem:createParticle(
      {
         flags = "water",
         velocityX = 256,
         velocityY = 480,
         color = { 1, 0, 0.1, 1 },
         x = 0,
         y = 0,
         lifetime = 32.0
      }
    )
    end

timer.performWithDelay( 20, onTimer, 0 )