Permanent
Creation

RPGツクールXP/VX用のRGSS素材です。
一部英語版対応です。 (A few materials can be used for English RPG MAKER XP/VX.)
競合率はルファーの独断と偏見なのでたまにハズレます。


#==============================================================================
# ■ 画面をひたすら撮る
#------------------------------------------------------------------------------
#  起動している限りずっと画面をキャプチャし続け、それを連番BMPに保存します。
# (C) ルファー
# WebSite  https://tkoolerlufar.pages.dev/
#==============================================================================

=begin
  =対応RGSS
  2

  =必要なライブラリ
  DIB 出力ライブラリ

  =他の素材との競合の可能性
  !.. 多分大丈夫

  =使い方
  オープニングデモをツクールのイベントで組んで
  この素材で連番BMPを作り、
  フリーソフト使ってAVIを作って、それを自サイトにPVとして公開したりできます。
  62行目以降の数値を変えれば連番BMPの撮り方を変えられます。
  数値は半角で入力してください。テンキーボードを使えば間違いないと思います。

  =設定項目
  *キャプチャスイッチ
  ・・・これを 0 以外にすると画面をキャプチャします。0 ならキャプチャしません。
  *幅
  ・・・保存するBMPの幅です。
  大きくすると処理が遅くなりますが、AVIにしたときに高解像度になります。
  *高さ
  ・・・保存するBMPの高さです。
  処理とAVIの解像度については幅と同じ。
  *キャプチャ間隔
  ・・・1に近いほど頻繁にBMP出力します。
  大きくすると「モーションぼかし」でごまかすようになります。
  「間隔」ではなく「頻度」で指定したい場合、
  ゲームのフレームレートを「頻度」で割ると
  1秒間にその数だけキャプチャするようになります。
  (ただしキャプチャ頻度はゲームのフレームレートの約数であること)
  例えば60FPSのゲームでキャプチャ間隔 60/30 とすれば 30FPS になります。
  *キャプチャ方法
  ・・・0なら撮るたびにファイルに書き出します。
  1ならいったん撮ったフレームをメモリに記憶し、
  空きメモリがなくなったときや F5 キーを押したときに、
  それらを一斉にファイルへ書き出します。
  0ならメモリ節約になります。1なら席をはずすときなどにまとめて書き出せます。

  =更新履歴
  2010/04/13 公開

  =再定義しているメソッド
  Graphics#update (エイリアス使用)
=end
#----------------------------------------------------------------------------
# ◇ Graphics モジュール
#----------------------------------------------------------------------------
module Graphics
  #--------------------------------------------------------------------------
  # ○ 素材ユーザーによる設定項目
  #--------------------------------------------------------------------------
  LufarSnap = 0                 # キャプチャスイッチ
  LufarSnap_Width = 320         # 幅
  LufarSnap_Height = 240        # 高さ
  LufarSnap_Interval = 2        # キャプチャ間隔
  LufarSnap_Method = 1          # キャプチャ方法
  #--------------------------------------------------------------------------
  # ○ クラス変数
  #--------------------------------------------------------------------------
  @@_LufarSnap_bitmap = nil
  @@_LufarSnap_frames = Array.new
  @@_LufarSnap_written_number = 0
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  instance_eval do
    unless defined? _LufarSnap_PrototypeOfUpdating
      alias _LufarSnap_PrototypeOfUpdating update
    end
  end
  def self.update
    self._LufarSnap_PrototypeOfUpdating
    return if LufarSnap == 0
    if @@_LufarSnap_bitmap.nil? or @@_LufarSnap_bitmap.disposed?
      @@_LufarSnap_bitmap = Bitmap.new(LufarSnap_Width, LufarSnap_Height)
    end
    bmp = nil
    loop do
      begin
        bmp = self.snap_to_bitmap
        break
      rescue RGSSError
        raise if $!.message !~ /^failed to create /
        self._LufarSnap_flush
      end
    end
    rect = bmp.rect
    ## 横長なら
    if bmp.width * LufarSnap_Height > bmp.height * LufarSnap_Width
      rect.y =
        (bmp.height - bmp.width * LufarSnap_Height / LufarSnap_Width) / 2
      rect.width = bmp.width
      rect.height = bmp.width * LufarSnap_Height / LufarSnap_Width
    ## 縦長なら
    elsif bmp.width * LufarSnap_Height < bmp.height * LufarSnap_Width
      rect.x =
        (bmp.width - bmp.height * LufarSnap_Width / LufarSnap_Height) / 2
      rect.width = bmp.height * LufarSnap_Width / LufarSnap_Height
      rect.height = bmp.height
    end
    if self.frame_count % LufarSnap_Interval != 0
      @@_LufarSnap_bitmap.stretch_blt(
        @@_LufarSnap_bitmap.rect, bmp, rect,
        255 / (self.frame_count % LufarSnap_Interval))
      bmp.dispose
    else
      @@_LufarSnap_bitmap.stretch_blt(
        @@_LufarSnap_bitmap.rect, bmp, rect,
        255 / LufarSnap_Interval)
      bmp.dispose
      case LufarSnap_Method
      when 0
        File.delete("Snap") if FileTest.file?("Snap")
        Dir.mkdir("Snap") if not FileTest.exist?("Snap")
        @@_LufarSnap_bitmap.write_to_bmpfile(
          sprintf("Snap/%010d.bmp",
          (self.frame_count & 0xFFFF_FFFF) / LufarSnap_Interval),
          false)
        self.frame_reset
      when 1
        @@_LufarSnap_frames.push(@@_LufarSnap_bitmap)
        @@_LufarSnap_bitmap = nil
        _LufarSnap_flush if Input.press?(Input::F5)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ○ スナップのフラッシュ
  #--------------------------------------------------------------------------
  def self._LufarSnap_flush
    sprite = nil
    File.delete("Snap") if FileTest.file?("Snap")
    Dir.mkdir("Snap") if not FileTest.exist?("Snap")
    n = @@_LufarSnap_frames.length
    loop do
      begin
        sprite = Sprite.new
        break
      rescue RGSSError
        raise if $!.message !~ /^failed to create /
        bmp = @@_LufarSnap_frames.pop
        bmp.write_to_bmpfile(
          sprintf("Snap/%010d.bmp",
          @@_LufarSnap_written_number + @@_LufarSnap_frames.length + 1), false)
        bmp.dispose
      end
    end
    sprite.z = 077777
    loop do
      begin
        sprite.bitmap = Bitmap.new(self.width, self.height)
        break
      rescue RGSSError
        raise if $!.message !~ /^failed to create /
        bmp = @@_LufarSnap_frames.pop
        bmp.write_to_bmpfile(
          sprintf("Snap/%010d.bmp",
          @@_LufarSnap_written_number + @@_LufarSnap_frames.length + 1), false)
        bmp.dispose
      end
    end
    until (bmp = @@_LufarSnap_frames.pop).nil?
      sprite.bitmap.clear
      sprite.bitmap.fill_rect(sprite.bitmap.rect,
        Color.new(0.0, 0.0, 0.0, 128.0))
      sprite.bitmap.draw_text(sprite.bitmap.rect,
        sprintf(
          "撮った画面をファイルに書き出しています・・・。残り %d 枚",
          @@_LufarSnap_frames.length + 1), 1)
      self.frame_reset
      self._LufarSnap_PrototypeOfUpdating
      self.frame_count -= 1
      bmp.write_to_bmpfile(sprintf("Snap/%010d.bmp",
        @@_LufarSnap_written_number + @@_LufarSnap_frames.length + 1), false)
      bmp.dispose
    end
    @@_LufarSnap_written_number += n
    sprite.bitmap.clear
    sprite.bitmap.fill_rect(sprite.bitmap.rect,
      Color.new(0.0, 0.0, 0.0, 128.0))
    sprite.bitmap.draw_text(sprite.bitmap.rect,
      sprintf(
        "書き出しが終わりました。F5キーでゲームに戻ります。",
        @@_LufarSnap_frames.length + 1), 1)
    f = false
    loop do
      self._LufarSnap_PrototypeOfUpdating
      Input.update
      self.frame_count -= 1
      if Input.press?(Input::F5)
        f = true
      elsif f
        break
      end
    end
    sprite.bitmap.dispose
    sprite.dispose
  end
end

戻る