• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • Eevee Expo's webhost has been having technical issues since Nov. 20th and you might be unable to connect to our site. Staff are also facing issues connecting, so please send a DM to Cat on-site or through Discord directly for faster service!
Resource icon

v21.1 Darkness Effect Management 1.0

This resource pertains to version 21.1 of Pokémon Essentials.
Pokémon Essentials Version
v21.1 ✅
Also compatible with
  1. v21
This script is designed to implement and manage a dynamic darkness effect in the game, adding a semi-transparent black layer that can vary in opacity and adapt to different scenarios. It is useful for creating immersive atmospheres, such as nighttime environments, shadowy dungeons, weather events, or any scene requiring lighting adjustments.

Main Features

  1. Darkness Creation:
    • Generates a dark layer using a Sprite that covers the entire screen.
    • The layer has a high depth (z) to ensure it always appears above other graphical elements.
  2. Opacity Control:
    • Allows direct adjustment of the darkness intensity with a numeric value (opacity) ranging from 0 (fully transparent) to 255 (fully opaque).
  3. Smooth Transitions:
    • Includes a function to perform gradual opacity transitions (fade_to), useful for effects like progressive darkening or gradual brightening during specific scenes.
  4. Management and Reuse:
    • Provides global methods to initialize, adjust, fade, and release the darkness layer when no longer needed.
    • A function ensures the effect is properly initialized (ensureDarkness), avoiding errors during gameplay.
  5. Optimization:
    • Resources associated with the effect are properly released using the dispose method, helping prevent performance issues.

Expected Usage

  • Atmosphere: Dynamically change the intensity of darkness to reflect ambient lighting changes.
  • Narrative Scenes: Use opacity transitions to add drama to key events in the game.
  • Gameplay: Integrate the effect into mechanics, such as reducing visibility during specific events or in areas where lighting is part of the challenge.

Global Methods

  • setDarknessIntensity(value): Instantly adjusts the opacity of the darkness.
  • DarkenessIntensityFade(value_one, value_two): Gradually changes the opacity from the current level to value_one over value_two frames.
  • disposeDarkness: Releases resources associated with the darkness effect.
  • recallDarkness: Reinitializes the darkness effect if it needs to be reused.
  • ensureDarkness: Verifies and initializes the darkness layer if it doesn’t already exist.
This script is a flexible tool to enhance player immersion by providing precise control over lighting effects in the game.


SCRIPT:

Ruby:
Expand Collapse Copy
# Clase para manejar el efecto de oscuridad en el juego
class DarknessEffect
  attr_reader :sprite
 
  def initialize
    @sprite = Sprite.new
    @sprite.z = 9999  # Asegura que esté por encima de otros elementos
  end
 
  def create_darkness_bitmap
    @sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
    @sprite.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0, 0, 0))
  end
 
  # Getter y setter para la opacidad
  def opacity=(value)
    @sprite.opacity = value
  end
 
  def opacity
    @sprite.opacity
  end
 
  # Cambia gradualmente la opacidad
  def fade_to(target_opacity, duration = 60)
    start_opacity = @sprite.opacity
    duration.times do |i|
      @sprite.opacity = start_opacity + (target_opacity - start_opacity) * i / duration
      Graphics.update
    end
  end
 
  def dispose
    @sprite.dispose if @sprite
  end
   def ensure_darkness_initialized
    # Check if the sprite doesn't exist or has been disposed
    if @sprite.nil? || @sprite.disposed?
      create_darkness_bitmap
      return true
    end
    false
  end
end

# Inicialización global del efecto de oscuridad
$game_darkness_effect ||= DarknessEffect.new



#Set Darkness value immediately
def setDarknessIntensity(value)
  $game_darkness_effect.opacity = value
end

#Darkness value_one, applies with fade effect of value_two frames.
def DarkenessIntensityFade(value_one, value_two)
  $game_darkness_effect.fade_to(value_one, value_two) 
end


#Dispose all darkness system
def disposeDarkness
  $game_darkness_effect.dispose
end


#Reinitialize Darkness System
def recallDarkness
    $game_darkness_effect.initialize
    $game_darkness_effect.create_darkness_bitmap
end
 

#Checks if Darkness System is complete
def ensureDarkness
  $game_darkness_effect.ensure_darkness_initialized
end

#Recreates only the darkeness bitmap.
def recallDarkSprite
  $game_darkness_effect.create_darkness_bitmap
end

Use example based on conditionals (game variable, or internal ruby variables, same works)
The system requires parallel process event for persistent darkness level data.


1d1bc4_859244c88c7a4ed7ab291a55a03debb9~mv2.png


1d1bc4_79f299599b7e41c692b7845d532df6ad~mv2.png

On exit of map, will dispose the Darkness Effect:

1d1bc4_6200fc168fc2412f8703141950413147~mv2.png
Credits
IgnathiusNZX
Author
IgnathiusNZX
Views
497
First release
Last update

Ratings

0.00 star(s) 0 ratings
Back
Top