Getting Started with the Particle Emitter

A particle emitter can be added to any project that uses the Sprite Kit framework. Xcode provides you with several emitter templates to add to your app. Or you can create new emitter programmatically and insert it directly into your app.

Adding an Emitter to a Project

Before adding a particle emitter to your project, you must have a Sprite Kit–enabled project. You can either create a new Sprite Kit project or add Sprite Kit to an existing project. To create a new project, you can find the Sprite Kit project template in the Application section for both iOS and OS X.

../Art/spritekit_project_2x.png../Art/spritekit_project_2x.png

Start developing a software product by creating a project.

  1. Choose File > New > New Project.

  2. Select the project template for your iOS or OS X product, and click Next.

  3. Enter the product name and other project details, and click Next.

  4. Specify the project’s container and its location in your file system, and click Save.

All software products require a project. The project organizes the files and resources needed to build one or more products, such as apps, plug-ins, and command-line tools.

The New Project dialog displays platforms, template families, project templates, and a description for the selected project template. In the project options pane you enter information required by the template to generate the project, such as the product name.

In the Save dialog you specify the container (one of your open projects or workspaces, and a group within it) and file-system location for the new project before completing the operation. For example, you can indicate that the container of the project be a project within your workspace instead of the workspace itself.

After saving the project, Xcode places a folder containing the new project’s files at the location you specified.

Once you’ve created a project, you can add new source files and begin writing code.

If you have an existing project and want to add particle emitters to the project, you need to add the Sprite Kit framework to your project.

Add a framework bundle to a project in order to incorporate the framework’s features into your product.

  1. In the project navigator, select the project or group within a project to which you want to add the framework.

  2. Choose File > Add Files to “<App_Name>”.

  3. Select the framework bundle, and click Add.

The frameworks you add this way are third-party-built bundles containing the framework’s object code and runtime resources. See related articles for information about linking to a framework without adding it to the project.

After you add the framework, Xcode configures the targets in your project to link them to the framework just added.

For your convenience, Xcode is preinstalled with eight particle emitter templates. See Table 1-1 for a description of each particle emitter template.

bullet
To add a particle emitter to a project
  1. Choose File > New > File.

  2. Choose Resource > SpriteKit Particle File.

  3. Select the particle template from the drop-down menu, and click Next.

  4. Enter a name for the emitter in the Save As field.

  5. Select the checkbox associated with your project in the Targets area.

Table 1-1  Particle emitter templates

Template name

Description

Bokeh

Hexagonal particles that grow and blur before fading out at the end of their life cycle.

Fire

A small fire effect that you would see in a fireplace or campfire.

Fireflies

Short-lived yellow particles that randomly move a short distance while growing and blurring before fading out at the end of their life cycle.

Magic

Short-lived green particles that randomly move a short distance while growing and blurring before fading out at the end of their life cycle.

Rain

Nonmorphing particles that start at the top of the emitter and move toward the bottom of the screen. Each particle moves at a different speed.

Smoke

Large black particles that start at the bottom of the emitter and move toward the top of the screen. As the particle moves, it slowly fades out.

Snow

White, diffuse, round particles that start at the top of the emitter and move toward the bottom of the screen. Each particle is a different size and moves at a different speed.

Spark

Sends short-lived, golden particles in 360 degrees, centered around the emitter.