类型 函数 库 display.* 返回值 EmitterObject 修订 版本 2024.3703 关键词 newEmitter 另请参阅 EmitterObject:start() EmitterObject:stop() EmitterObject:pause()
此函数创建一个 EmitterObject,用于显示粒子效果。
发射器发射的粒子除非其生命周期结束,否则**不会**自动移除,即使它们移出屏幕也不会被销毁。如果您正在使用 Composer 进行场景管理,则使用 display.newEmitter()
创建的发射器应插入到 Composer 场景视图(或场景视图的子组)中,以便在场景退出时将其移除。如果您未使用 Composer,则可以使用 object:removeSelf() 或 display.remove() 手动销毁发射器以移除其生成的所有粒子。
在 macOS 上,可以使用 Particle Designer 将发射器设计并输出为
display.newEmitter( emitterParams [, baseDir] )
表。 发射器的参数表。有关有效属性列表,请参阅 EmitterObject 文档。
常量。 指定粒子发射器图像文件所在的基目录。选项包括 system.ResourceDirectory
、system.DocumentsDirectory
、system.ApplicationSupportDirectory
、system.TemporaryDirectory
和 system.CachesDirectory
。默认为 system.ResourceDirectory
。
-- Table of emitter parameters local emitterParams = { startColorAlpha = 1, startParticleSizeVariance = 53.47, startColorGreen = 0.3031555, yCoordFlipped = -1, blendFuncSource = 770, rotatePerSecondVariance = 153.95, particleLifespan = 0.7237, tangentialAcceleration = -144.74, finishColorBlue = 0.3699196, finishColorGreen = 0.5443883, blendFuncDestination = 1, startParticleSize = 50.95, startColorRed = 0.8373094, textureFileName = "fire.png", startColorVarianceAlpha = 1, maxParticles = 256, finishParticleSize = 64, duration = -1, finishColorRed = 1, maxRadiusVariance = 72.63, finishParticleSizeVariance = 64, gravityy = -671.05, speedVariance = 90.79, tangentialAccelVariance = -92.11, angleVariance = -142.62, angle = -244.11 } -- Create the emitter local emitter = display.newEmitter( emitterParams ) -- Center the emitter within the content area emitter.x = display.contentCenterX emitter.y = display.contentCenterY
-- Require the JSON library for decoding purposes local json = require( "json" ) -- Read the exported Particle Designer file (JSON) into a string local filePath = system.pathForFile( "fire.json" ) local f = io.open( filePath, "r" ) local emitterData = f:read( "*a" ) f:close() -- Decode the string local emitterParams = json.decode( emitterData ) -- Create the emitter with the decoded parameters local emitter = display.newEmitter( emitterParams ) -- Center the emitter within the content area emitter.x = display.contentCenterX emitter.y = display.contentCenterY