Save-Point
FadingSprite XP - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: FadingSprite XP (/thread-8626.html)



FadingSprite XP - kyonides - 01-06-2023

FadingSprite XP

by Kyonides


Introduction

Thinking Have you ever needed a script that could let you make your sprite appear and disappear at regular intervals without forcing you to learn how to code?
Today gotta be your lucky day then! Grinning

Just follow 2 instructions included in my comments and you will be fine! Winking

The Script

Code:
# * FadingSprite * #
#   Scripter : Kyonides Arkanthes
#   2023-01-05

# * Create a New Fading Sprite - 2 Options
# @sprite = FadingSprite.new(Frames)
# @sprite = FadingSprite.new(Frames, Viewport)

# * Update the Fading Sprite's Opacity
# @sprite.update

class FadingSprite < Sprite
  def initialize(total_frames, vp=nil)
    super(vp)
    self.opacity = 0
    @frames = total_frames
    @timer = 0
    @fade_type = :in
  end

  def update
    if @timer > 0
      @timer -= 1
      return if @timer > 0
      @fade_type = @next_fade == :in ? :in : :out
      return
    elsif @fade_type == :in
      self.opacity += 16
      if self.opacity == 255
        @fade_type = nil
        @next_fade = :out
      end
      return
    elsif @fade_type == :out
      self.opacity -= 16
      if self.opacity == 0
        @fade_type = nil
        @next_fade = :in
      end
      return
    end
    @timer = @frames
  end
end

Here is a Test Scene for RMXP (HiddenChest).

Code:
class AnyButtonScene
  def main
    $data_system = load_data("Data/System.rxdata")
    $game_system = Game_System.new
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.title($data_system.title_name)
    @title = Sprite.new
    @title.y = 40
    @title.bitmap = b1 = Bitmap.new(640, 44)
    b1.font.size = 40
    b1.draw_text(0, 0, 640, 40, Game::DATA["Title"], 1)
    @label = FadingSprite.new(Graphics.frame_rate / 2)
    @label.y = 436
    @label.opacity = 0
    @label.bitmap = b2 = Bitmap.new(640, 32)
    b2.font.size = 28
    b2.draw_text(0, 0, 640, 28, "Press Any Button", 1)
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    @label.bitmap.dispose
    @label.dispose
    @title.bitmap.dispose
    @title.dispose
    @sprite.bitmap.dispose
    @sprite.dispose
  end

  def update
    @label.update
    if Input.trigger_any?
      $game_system.se_play($data_system.decision_se)
      $scene = Scene_Title.new
    end
  end
end

I got to admit here that you will need to make your own test scene for other RGSS based engines. Happy with a sweat

Terms & Conditions

Free for user ANYWHERE. Grinning Beer 
Just keep in mind that you should mention me in your game credits. Two Thumbs Up! 
I really hope this script won't be the only one you include in your game project. Winking