Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions particles/particlefx_set_get/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
.defold/*
.defignore
18 changes: 18 additions & 0 deletions particles/particlefx_set_get/all.texture_profiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
path_settings {
path: "**"
profile: "Default"
}
profiles {
name: "Default"
platforms {
os: OS_ID_GENERIC
formats {
format: TEXTURE_FORMAT_RGBA
compression_level: BEST
compression_type: COMPRESSION_TYPE_DEFAULT
}
mipmaps: false
max_texture_size: 0
premultiply_alpha: true
}
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added particles/particlefx_set_get/assets/images/smoke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions particles/particlefx_set_get/assets/particles.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
animations {
id: "coin"
images {
image: "/assets/images/coin/dcoin_1.png"
}
images {
image: "/assets/images/coin/dcoin_2.png"
}
images {
image: "/assets/images/coin/dcoin_3.png"
}
images {
image: "/assets/images/coin/dcoin_4.png"
}
images {
image: "/assets/images/coin/dcoin_5.png"
}
playback: PLAYBACK_LOOP_FORWARD
fps: 8
}
animations {
id: "ship_red"
images {
image: "/assets/images/coin/dcoin_1.png"
}
playback: PLAYBACK_NONE
}
animations {
id: "smoke"
images {
image: "/assets/images/smoke.png"
}
playback: PLAYBACK_NONE
}
animations {
id: "ship_dark"
images {
image: "/assets/images/smoke.png"
}
playback: PLAYBACK_NONE
}
extrude_borders: 2
29 changes: 29 additions & 0 deletions particles/particlefx_set_get/assets/sprites.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
animations {
id: "coin"
images {
image: "/assets/images/playerShip1_red.png"
}
playback: PLAYBACK_NONE
}
animations {
id: "ship_red"
images {
image: "/assets/images/playerShip1_red.png"
}
playback: PLAYBACK_NONE
}
animations {
id: "smoke"
images {
image: "/assets/images/enemyBlack1.png"
}
playback: PLAYBACK_NONE
}
animations {
id: "ship_dark"
images {
image: "/assets/images/enemyBlack1.png"
}
playback: PLAYBACK_NONE
}
extrude_borders: 2
5 changes: 5 additions & 0 deletions particles/particlefx_set_get/assets/text24.font
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
font: "/assets/SourceSansPro-Semibold.ttf"
material: "/builtins/fonts/font-df.material"
size: 24
output_format: TYPE_DISTANCE_FIELD
characters: " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
Binary file added particles/particlefx_set_get/doc/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added particles/particlefx_set_get/doc/particlefx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions particles/particlefx_set_get/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
tags: particles
title: ParticleFX emitter properties
brief: This example shows how to get and set ParticleFX emitter image, animation, and material at runtime.
author: Defold Foundation
scripts: particlefx_set_get.script, particlefx_glow.fp
thumbnail: thumbnail.png
---

Since Defold 1.12.2 you can use `go.get()` and `go.set()` on individual ParticleFX emitters by passing `keys = { "..." }`.

This example focuses on this feature. It toggles a ParticleFX between two setups and shows the properties of the active emitters in the labels.

## Setup

1. Example consists of one game object in the collection having:

- script `particlefx_set_get.script`
- ParticleFX component named `#particles`
- 2 label components: `#label_core` and `#label_spark`
![Outline](doc/outline.png)

2. The ParticleFX:

- has two emitters: `emitter_top` and `emitter_bottom`
![ParticleFX](doc/particlefx.png)

3. The script has the resources exposed as properties:

- `particles_atlas`
- `sprites_atlas`
- `default_material`
- `glow_material`

This makes it easy to switch the emitter `image` and `material` directly from code.

4. The example uses 2 atlases with given animations:

- the `particles.atlas` with `coin` and `smoke` animations
- the `sprites.atlas` with `ship_red` and `ship_dark` animations

The atlases are set up to contain the animation ids used by the script, so the example can switch between the two setups without extra transition logic.

## How it works

The script keeps two hardcoded setups and toggles between them whenever you click or tap:

1. `particles.atlas` + glow material
`emitter_top` uses `coin`
`emitter_bottom` uses `smoke`
2. `sprites.atlas` + default particle material
`emitter_top` uses `ship_red`
`emitter_bottom` uses `ship_dark`

When the setup changes, the script:

1. stops the ParticleFX
2. calls `set_emitter_properties()` for each emitter to set `image`, `animation`, and `material`
3. calls `get_emitter_properties()` to read the current values back with `go.get()`
4. writes the values into the two labels
5. plays the ParticleFX again

The helper function `set_emitter_properties()` applies properties per emitter by passing the emitter id in `keys`:

```lua
go.set("#particles", "image", image, { keys = { "emitter_top" } })
go.set("#particles", "animation", animation, { keys = { "emitter_top" } })
go.set("#particles", "material", material, { keys = { "emitter_top" } })
```

The helper function `get_emitter_properties()` uses the same `keys` pattern with `go.get()` and writes the result into the labels, so the example shows which values are currently active for each emitter.

One important limitation: **emitter property changes only affect the next play**. That is why the script stops and plays the ParticleFX around each property update.
Loading