MaplyParticleSystem

Objective-C

@interface MaplyParticleSystem : NSObject

Swift

class MaplyParticleSystem : NSObject

A particle system is used to spawn large numbers of small moving objects.

The particle system defines what the objects are and how they’re controlled. Actual data is handled through the MaplyParticleBatch.

You set up a particle system and then add MaplyParticleBatches via a view controller.

  • Name of the particle system.

    The particle system name is used for performance debugging.

    Declaration

    Objective-C

    @property (nonatomic, strong) NSString *_Nullable name;

    Swift

    var name: String? { get set }
  • The type of the particle system.

    At present particle systems are just point geometry.

    Declaration

    Objective-C

    @property (nonatomic) MaplyParticleSystemType type;

    Swift

    var type: MaplyParticleSystemType { get set }
  • Position shader for two stage particles.

    If there is a position shader then it is run first and particle data is then shared between this shader and the regular shader.

    Declaration

    Objective-C

    @property (nonatomic, strong) MaplyShader *_Nullable positionShader;

    Swift

    var positionShader: MaplyShader? { get set }
  • Shader to use for rendering particles.

    This can either be a single stage shader or it can be part of a two stage shader with the positionShader.

    Declaration

    Objective-C

    @property (nonatomic, strong) MaplyShader *_Nullable renderShader;

    Swift

    var renderShader: MaplyShader? { get set }
  • Individual particle lifetime.

    The created particles will last only a certain amount of time.

    Declaration

    Objective-C

    @property (nonatomic) NSTimeInterval lifetime;

    Swift

    var lifetime: TimeInterval { get set }
  • The base that particle time is measured from.

    Individual particles will measure their own lifetime against this base value.

    Declaration

    Objective-C

    @property (nonatomic) NSTimeInterval baseTime;

    Swift

    var baseTime: TimeInterval { get set }
  • Total number of particles to be represented at once.

    This is the most particles we’ll have on the screen at any time. Space will be allocated for them, so don’t overdo it.

    Declaration

    Objective-C

    @property (nonatomic) int totalParticles;

    Swift

    var totalParticles: Int32 { get set }
  • Batch size for MaplyParticleBatch.

    Particles need to be created in large batches for efficiency. This is the size of individual batches.

    Only for OpenGL ES. Metal does particles as one big batch.

    Declaration

    Objective-C

    @property (nonatomic) int batchSize;

    Swift

    var batchSize: Int32 { get set }
  • Metal only. Size of a single to be passed in to the calculation and rendering shaders.

    Declaration

    Objective-C

    @property (nonatomic) int vertexSize;

    Swift

    var vertexSize: Int32 { get set }
  • Turn on/off the continuous rendering for particles.

    Normally particle systems force the renderer to draw every frame. That’s how the particles move. You can turn that behavior off by setting this to false.

    Declaration

    Objective-C

    @property (nonatomic) _Bool continuousUpdate;

    Swift

    var continuousUpdate: Bool { get set }
  • Initialize a particle system with a name.

    The particle system needs the name for performance and debugging. The rest of the values can left to their defaults.

    Declaration

    Objective-C

    - (nonnull instancetype)
        initWithName:(NSString *_Nonnull)name
               viewC:(NSObject<MaplyRenderControllerProtocol> *_Nonnull)viewC;
  • Add an attribute we’ll be expecting in each batch.

    Adds an attribute name and type which will be present in each batch.

    OpenGL ES Only. Metal handles things as blocks of memory.

    Declaration

    Objective-C

    - (void)addAttribute:(NSString *_Nonnull)attrName
                    type:(MaplyShaderAttrType)type;

    Swift

    func addAttribute(_ attrName: String, type: MaplyShaderAttrType)
  • For two stage shaders, these are the varying outputs from one shader to the next.

    Two stage shaders run a position shader and then a regular render shader from the position output. Add any varying values you want to share per vertex from the former to the latter.

    OpenGL ES Only. Metal does this more simply.

    Declaration

    Objective-C

    - (void)addVarying:(NSString *_Nonnull)varyAttrName
             inputName:(NSString *_Nonnull)inputName
                  type:(MaplyShaderAttrType)type;

    Swift

    func addVarying(_ varyAttrName: String, inputName: String, type: MaplyShaderAttrType)
  • Add a texture to the particle system.

    All the textures will be handed over to the shader.

    Declaration

    Objective-C

    - (void)addTexture:(id _Nonnull)image;

    Swift

    func addTexture(_ image: Any)
  • Draw these particles to the given render target.

    Rather than being drawn to the screen, these particles will be drawn to the offscreen render target.

    Declaration

    Objective-C

    - (void)setRenderTarget:(MaplyRenderTarget *_Nonnull)renderTarget;

    Swift

    func setRenderTarget(_ renderTarget: MaplyRenderTarget)