じ☆ve冰风 发表于 昨天 15:52

Glitch Effects v1.0

Pasp's Glitch Effects v1.0




https://forums.rpgmakerweb.com/attachments/glitch_example2-png.367847/


This script can be used to create a "glitching" effect over the current screen, with the option to add a sound effect as well.

Instructions:
Place script below Materials and above Main

Use the script call "show_glitch" when you want to have a glitching effect. "show_glitch" can be used with the defaults, or with the arguments intensity, duration, volume, and pitch in that order.

For example:
                Ruby:       
show_glitch(10,20,100,50)

This will create a glitch effect with a maximum pixel shift of 10 pixels that lasts for 20 frames, with a sound effect volume of 100 and sound effect pitch of 50.
The default values are intensity = 5, duration = 3, volume = 100, and pitch = 100.

User Settings:
The user can set the ID for a switch to turn the glitch sound effect on and off using GLITCH_AUDIO_SWITCH. Setting the switch ID to 0 will disable glitch sound effects.
The sound effect file name is set using the variable AUDIO_FILE. The sound effect must be in the SE folder.
The sound effect pitch and volume can also be randomly tweaked when RANDOM_PITCH and RANDOM_VOL are set to true, for extra glitchiness.

History:
June 10, 2026: v1.0 release

Terms:
Can be used in free and commercial games or modified however you like, but please credit!

Code:
Spoiler                Ruby:       
#===============================================================================
# Pasp's Glitch Effects v1.0
#-------------------------------------------------------------------------------
# Can be used to create a "glitching" effect over the current screen, with
# the option to add a sound effect as well.
#-------------------------------------------------------------------------------
# Instructions:
# Place script below Materials and above Main
#
# Use the script call "show_glitch" when you want to have a glitching effect
# "show_glitch" can be used with the defaults, or with the arguments intensity,
# duration, volume, and pitch in that order.
#
# For example: show_glitch(10,20,100,50)
# This will create a glitch effect with a maximum pixel shift of 10 pixels that
# lasts for 20 frames, with a sound effect volume of 100 and sound effect pitch
# of 50.
# Default values are intensity = 5, duration = 3, volume = 100, and pitch = 100
#-------------------------------------------------------------------------------
# History:
# June 10, 2026: v1.0 release
#-------------------------------------------------------------------------------
# Terms:
# Can be used in free and commercial games or modified however you like, but
# please credit!
#===============================================================================
module GLITCH_USER_SETTINGS

# Switch to turn on and off glitch sound effects. Set to 0 to disable sound
# effects altogether
GLITCH_AUDIO_SWITCH = 0

# Name of audio file to use for glitch effects. Must be in the SE folder
AUDIO_FILE = ""
   
# Set to "true" to randomize glitch sound effect pitch by +/- 25; otherwise
# set to false
RANDOM_PITCH = true

# Set to "true" to randomize glitch sound effect volume by +/- 25; otherwise
# set to false
RANDOM_VOL = true

end #GLITCH_USER_SETTINGS
#===============================================================================
# Edit below at your own risk!
#===============================================================================
module Glitch
#-----------------------------------------------------------------------------
# * Apply Glitch Effect
#   Creates the glitched bitmap from a snap of the current screen
#-----------------------------------------------------------------------------
def self.apply_glitch_effect(intensity)
    source = Graphics.snap_to_bitmap
    result = Bitmap.new(Graphics.width, Graphics.height)
   
    y = 0
    while y < Graphics.height
      shift = rand(intensity * 2 + 1) - intensity
      
      src_rect = Rect.new(0, y, Graphics.width, 1)
      result.blt(shift, y, source, src_rect)
      
      y += 1
    end
   
    source.dispose
    return result
end

#-----------------------------------------------------------------------------
# * Play Glitch SE
#   Plays a glitch sound effect, if enabled
#-----------------------------------------------------------------------------
def self.play_glitch_se(volume,pitch)
    return if GLITCH_USER_SETTINGS::GLITCH_AUDIO_SWITCH <= 0
    return unless $game_switches
    return if GLITCH_USER_SETTINGS::AUDIO_FILE.strip.empty?
   
    audio_path = "Audio/SE/" + GLITCH_USER_SETTINGS::AUDIO_FILE
   
    rng_vol = volume
    if GLITCH_USER_SETTINGS::RANDOM_VOL
      rng_vol = [[(rand(51) + volume - 25),100].min,0].max
    end
      
    rng_pitch = pitch
    if GLITCH_USER_SETTINGS::RANDOM_PITCH
      rng_pitch = [[(rand(51) + pitch - 25),150].min,50].max
    end
   
    Audio.se_play(audio_path,rng_vol,rng_pitch)
end
end #Glitch

#===============================================================================
# ** Game_Interpreter
#===============================================================================
class Game_Interpreter
#-----------------------------------------------------------------------------
# * Show Glitch
#   Can be called to display glitch effect
#-----------------------------------------------------------------------------
def show_glitch(intensity=5,duration=3,volume=100,pitch=100)   
    Glitch.play_glitch_se(volume,pitch)
    bitmap = Glitch.apply_glitch_effect(intensity)
   
    glitch_sprite = Sprite.new
    glitch_sprite.bitmap = bitmap
    glitch_sprite.z = 999
    duration.times { Graphics.update }
   
    glitch_sprite.bitmap.dispose
    glitch_sprite.dispose
    glitch_sprite = nil
end
end





Pastebin link


本贴来自国际rpgmaker官方论坛作者:Pasp处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/glitch-effects-v1-0.183987/
页: [1]
查看完整版本: Glitch Effects v1.0