How I Made Simple Dynamic Effects For Shape Rush


How I Made the Dynamic Death Particles in Shape Rush

I wanted the enemy death effects to feel impactful and reflect the enemy's strength, moving beyond a simple, static explosion. Here's how I achieved dynamic particle bursts using Godot's GPUParticles2D and by dynamically setting their color in GDScript.

1. The GPUParticles2D Node and its Texture

The core of the particle system is Godot's GPUParticles2D node. This node is optimized for rendering many particles efficiently on the GPU.

  • Custom Texture: Instead of using a complex sprite sheet, I created a simple, small white square texture. This texture serves as the base "shape" for each particle. It's assigned directly to the Texture slot under the Drawing section of the GPUParticles2D node in the Inspector.
  • Why a white square? Using a white base allows for maximum flexibility. The particle system will take this white texture and tint it with any color I need, controlled directly from the script.

2. Dynamic Scaling and Coloring in GDScript

The real "excitement" comes from controlling the particles dynamically based on enemy strength and coloring them to match the enemy. In the enemy's death script, I calculate amount (how many particles) and lifetime (how long they last), and then set their color.

var combined_strength = (base_score * 0.3) + (base_hp * 0.35) + (tier * 0.35)
effect.amount = clamp(combined_strength * 0.3, 25, 100) # Scales particle count 
effect.lifetime = clamp(log(combined_strength + 1) * 0.7 - 1.5, 0.4, 4) 
effect.modulate = get_base_color() 
  • combined_strength: I define a single metric called combined_strength. This value combines the enemy's base_score, base_hp, and tier with specific weights. This makes the particle effect scale intelligently with overall enemy difficulty.
  • effect.amount:
    • The number of particles is combined_strength * 0.3. This means stronger enemies (higher combined_strength) produce more particles.
    • clamp(..., 25, 100) ensures the amount is always between a minimum of 25 (for a noticeable effect) and a maximum of 100 (to prevent visual clutter and performance issues).
  • effect.lifetime:
    • The particle duration uses a log function: log(combined_strength + 1) * 0.7 - 1.5.
    • The log function ensures that the lifetime scales non-linearly. This means:
      • Small increases in combined_strength (for weaker enemies) result in noticeable increases in lifetime.
      • Large increases in combined_strength (for stronger enemies) result in smaller, more gradual increases in lifetime. This prevents particles from lingering forever for super-strong enemies, keeping the screen clean.
    • clamp(..., 0.4, 4) sets the minimum lifetime to 0.4 seconds (so particles don't vanish instantly) and a maximum of 4 seconds (to prevent them from overstaying their welcome).
  • effect.modulate = get_base_color(): This is the key for coloring! The modulate property of the GPUParticles2D node directly tints the base white texture of the particles. By setting it to get_base_color() (which retrieves the enemy's own color), I ensure the particles burst out in the enemy's distinct color. This works automatically with Godot's default particle rendering, no custom fragment shader needed for just tinting

I had tried using a shader. However, it was too much work for a simple coloring issue. at the end, I had settled on a simple function that matches the color of the enemy: 

func get_base_color() -> Color:
    match color: 
        "RED":
            return Color(1, 0, 0)
        "BLUE":
            return Color(0.2, 0.6, 1)
        "PURPLE":
            return Color(0.6, 0.3, 0.9)
        "ORANGE":
            return Color(1, 0.5, 0.1)
          _:
            return Color.WHITE # Safety fall back 

The Result:

This setup allows for a highly dynamic and visually satisfying death effect where:

  • Weaker enemies produce a smaller, quicker burst of particles in their color.
  • Stronger, higher-tier enemies explode into a larger, longer-lasting cloud of particles, also matching their distinct color.

It adds a lot to the "excitement" and visual feedback in "Shape Rush"!

Get The Shape Rush

Leave a comment

Log in with itch.io to leave a comment.