Skip to content
Open
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
18 changes: 18 additions & 0 deletions factory/spawn_properties/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.
Binary file added factory/spawn_properties/assets/images/flame.png
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 factory/spawn_properties/assets/images/star2.png
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.
25 changes: 25 additions & 0 deletions factory/spawn_properties/assets/sprites.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
images {
image: "/assets/images/flame.png"
}
images {
image: "/assets/images/playerShip1_red.png"
}
images {
image: "/assets/images/enemyRed2.png"
}
images {
image: "/assets/images/enemyBlue4.png"
}
images {
image: "/assets/images/ufoGreen.png"
}
images {
image: "/assets/images/laserRed04.png"
}
images {
image: "/assets/images/meteorGrey_tiny1.png"
}
images {
image: "/assets/images/star2.png"
}
extrude_borders: 2
5 changes: 5 additions & 0 deletions factory/spawn_properties/assets/text48.font
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
font: "/assets/SourceSansPro-Semibold.ttf"
material: "/builtins/fonts/font.material"
size: 48
outline_alpha: 0.0
outline_width: 0.0
Binary file added factory/spawn_properties/collection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions factory/spawn_properties/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
tags: factory
title: Spawn enemies with script properties
brief: This example shows how to spawn enemy game objects using a factory component with different properties.
author: Defold Foundation
scripts: ship.script, enemy.script, spawner.script
thumbnail: thumbnail.png
---

This example shows how to dynamically spawn enemy game objects using a factory component with different properties. The setup consists of three main components: a player ship, enemy spawner, and different enemy types with customizable properties.

Press keys `1`, `2`, or `3` to spawn different enemy types.

Example collection consists of 2 game objects:

![Screenshot showing enemy types and spawner in action](collection.png)

### Ship
The red ship at the bottom that automatically moves and shoots. Consists of:
- A *Factory* component `bulletfactory` to spawn bullet game objects
- A *Script* `ship` that handles automatic movement (ping-pong animation) and bullet spawning every 0.25 seconds
- A *Sprite* component with the spaceship image

Bullets are simply animated upward and automatically deleted when they reach the top.

### Spawner
Controls enemy spawning with keyboard input. Consists of:
- A *Factory* `enemyfactory` to spawn enemies with different properties
- A *Label* `example_description` with instructions text displayed on top
- A *Script* `spawner` that spawns enemies.


The spawner script defines three different enemy types: `random`, `diagonal`, and `straight`.
Uses factory to create enemies with specific properties:

```lua
local properties = ENEMY_TYPES[enemy_type]
factory.create("#enemyfactory", position, nil, properties)
```

### Enemy Types

**Random Enemy** (Key 1):
- Green UFO sprite
- 1 health point
- Random horizontal movement that changes every second
- Speed: 40 horizontal, -100 vertical

**Diagonal Enemy** (Key 2):
- Red enemy sprite
- 2 health points
- Fixed diagonal movement
- Speed: 120 horizontal, -80 vertical

**Straight Enemy** (Key 3):
- Blue enemy sprite
- 3 health points
- Straight downward movement
- Speed: 0 horizontal, -40 vertical

### Enemy Script Properties
Properties defined in `enemy.script` control enemy behavior:
- `sprite` - Which sprite to display
- `health_points` - How many hits before destruction
- `speed` - Movement velocity vector
- `is_random` - Whether to use random movement changes

When enemies have `go.property` defined in their script, these properties are visible in the *Properties* pane and can be customized per enemy type.

Combine this example with other movement and physics examples to create a complete shoot'em up game!
265 changes: 265 additions & 0 deletions factory/spawn_properties/example/boom.particlefx
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
emitters {
id: "light"
mode: PLAY_MODE_ONCE
duration: 1.0
space: EMISSION_SPACE_WORLD
tile_source: "/assets/sprites.atlas"
animation: "star2"
material: "/builtins/materials/particlefx.material"
blend_mode: BLEND_MODE_ADD
max_particle_count: 1
type: EMITTER_TYPE_CIRCLE
properties {
key: EMITTER_KEY_SPAWN_RATE
points {
y: 10.0
}
}
properties {
key: EMITTER_KEY_SIZE_X
points {
y: 8.0
}
}
properties {
key: EMITTER_KEY_SIZE_Y
points {
y: 12.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_LIFE_TIME
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_SIZE
points {
y: 20.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_RED
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_GREEN
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_BLUE
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_ALPHA
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_SCALE
points {
y: 1.0
t_x: 0.25919977
t_y: 0.9658237
}
points {
x: 1.0
y: 0.023632
t_x: 0.9998886
t_y: 0.014926955
}
}
particle_properties {
key: PARTICLE_KEY_RED
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_GREEN
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_BLUE
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_ALPHA
points {
y: 0.0
t_x: 0.07194582
t_y: 0.99740857
}
points {
x: 0.11320755
y: 0.99277455
t_x: 0.99418455
t_y: 0.10768964
}
points {
x: 0.7112546
y: 0.555656
t_x: 0.5694311
t_y: -0.82203907
}
points {
x: 1.0
y: 0.0072254334
t_x: 0.4737472
t_y: -0.8806609
}
}
particle_properties {
key: PARTICLE_KEY_ANGULAR_VELOCITY
points {
y: 1.0
}
}
}
emitters {
id: "debris"
mode: PLAY_MODE_ONCE
duration: 1.0
space: EMISSION_SPACE_WORLD
tile_source: "/assets/sprites.atlas"
animation: "meteorGrey_tiny1"
material: "/builtins/materials/particlefx.material"
max_particle_count: 4
type: EMITTER_TYPE_CIRCLE
properties {
key: EMITTER_KEY_SPAWN_RATE
points {
y: 10.0
}
}
properties {
key: EMITTER_KEY_SIZE_X
points {
y: 8.0
}
}
properties {
key: EMITTER_KEY_SIZE_Y
points {
y: 12.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_LIFE_TIME
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_SPEED
points {
y: 50.0
}
spread: 20.0
}
properties {
key: EMITTER_KEY_PARTICLE_SIZE
points {
y: 10.0
}
spread: 5.0
}
properties {
key: EMITTER_KEY_PARTICLE_RED
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_GREEN
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_BLUE
points {
y: 1.0
}
}
properties {
key: EMITTER_KEY_PARTICLE_ALPHA
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_SCALE
points {
y: 1.0
t_x: 0.25919977
t_y: 0.9658237
}
points {
x: 1.0
y: 0.00553
}
}
particle_properties {
key: PARTICLE_KEY_RED
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_GREEN
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_BLUE
points {
y: 1.0
}
}
particle_properties {
key: PARTICLE_KEY_ALPHA
points {
y: 0.0
t_x: 0.07194582
t_y: 0.99740857
}
points {
x: 0.11320755
y: 0.99277455
t_x: 0.99418455
t_y: 0.10768964
}
points {
x: 0.7112546
y: 0.555656
t_x: 0.5694311
t_y: -0.82203907
}
points {
x: 1.0
y: 0.0072254334
t_x: 0.4737472
t_y: -0.8806609
}
}
particle_properties {
key: PARTICLE_KEY_ANGULAR_VELOCITY
points {
y: 1.0
}
}
}
Loading