Scene Credit script
Version 1.0
Author Jens of Zanicuud
Release Date 23/02/2012
Exclusive Script at RPG RPG RevolutionIntroduction A script which allow you to write your credit file in a .txt and then make RPGXP format it and show it as a scrolling text, with custom BGM and background.
Features Described in the script itself
Script CODE
#==============================================================================
#=#============================================================================
# #** Jens of Zanicuud credits script v 1.0
# # -free use, just credit
# # -free customization, however, posting on RRR the modified version is
# # mandatory
# # -you can find me on www.rpgrevolution.com
#=#============================================================================
#==============================================================================
#==============================================================================
# ** HOW TO USE:
# place a .txt file named as you like into Data folder and set CREDITS_FILE_NAME
# equal to that file name.
# Lines will be automatically arranged to fit the window width.
# Credits' scrolling speed can be set editing CREDITS_SCROLL_SPEED (default: 1)
# Credits will be written with font name, size and colour set by these constants:
#
# CREDITS_FONT_NAME_STANDARD #standard font name
# CREDITS_FONT_COLOR_STANDARD #standard font color
# CREDITS_FONT_SIZE_STANDARD #standard font size
#
# When CREDITS_TITLE_MARKER character is found into a line, that line is
# flagged as a title line, and then font name, colour and size are changed
# according to CREDITS_FONT_NAME_TITLE, CREDITS_FONT_COLOR_TITLE and
# CREDITS_FONT_SIZE_TITLE
# Set CREDITS_TITLE_MARKER as you can see in the example:
#
# CREDITS_TITLE_MARKER = '[marker character]'
# CREDITS_TITLE_MARKER_SUB = '[substitution character]'
#
# Marker character will be replaced by CREDITS_TITLE_MARKER_SUB when found
#
# Example:
#
# CREDITS_FILE_NAME = "new_credits.txt"
# CREDITS_TITLE_MARKER = '--'
# CREDITS_TITLE_MARKER_SUB = '*'
#
# <file new_credits.txt>
#
# -- Credits --
# me
# someone else
#
# -- Thank you --
#
# <output>
#
# * Credits * [formatted as title]
# me
# someone else
#
# * Thank you * [formatted as title]
#
# Ask for troubleshooting anytime.
#
# Jens of Zanicuud
#==============================================================================
#--------------------------------------------------------------------------
# * constants
#--------------------------------------------------------------------------
CREDITS_FONT_NAME_TITLE = "Fixed Miriam Transparent"
CREDITS_FONT_SIZE_TITLE = 26
CREDITS_FONT_NAME_STANDARD = "Fixed Miriam Transparent"
CREDITS_FONT_SIZE_STANDARD = 22
CREDITS_FONT_COLOR_TITLE = Color.new(230,230,0)
CREDITS_FONT_COLOR_STANDARD = Color.new(255,255,255)
CREDITS_SCROLL_SPEED = 1
CREDITS_FILE_NAME = "credits.txt"
CREDITS_TITLE_MARKER = '--'
CREDITS_TITLE_MARKER_SUB = '--'
#--------------------------------------------------------------------------
# * BGM
# set here the bgm to play in this scene. Name should be completed with
# file extension
#--------------------------------------------------------------------------
CREDITS_BGM_NAME = "Scene1.ogg"
CREDITS_BGM_VOLUME = 100
CREDITS_BGM_PITCH = 100
#--------------------------------------------------------------------------
# * Background Picture
# set here background picture name with extension. It must be a picture in
# Graphics/Pictures folder.
# If name is "", image won't be displayed
#--------------------------------------------------------------------------
CREDITS_BG_PICTURE_NAME = "Palmare.png"
#==============================================================================
# ** Window_Credits
#------------------------------------------------------------------------------
# a window which displays text files
#==============================================================================
class Window_Credits < Window_Base
#--------------------------------------------------------------------------
# * initialize
# filename: file to be read (must be a .txt located into Data folder)
# transparent: set true to make the window background transparent
#--------------------------------------------------------------------------
def initialize(filename,transparent = true)
super(0,-64,640,608)
#open file
file = File.new("Data/"+filename)
#read lines
@word_ary = file.readlines()
#create dummy bitmap
self.contents = Bitmap.new(width-32, height-32)
self.contents.font.name = CREDITS_FONT_NAME_STANDARD
self.contents.font.size = CREDITS_FONT_SIZE_STANDARD
#set opacity to zero if transparent
self.opacity = 0 if transparent
#close file
file.close()
#split sentences
prepare_words
#calculate number of sentences
@item_max = @word_ary.size
#refresh
refresh
end
#--------------------------------------------------------------------------
# * refresh
#--------------------------------------------------------------------------
def refresh
#clear old contents
self.contents.clear
#create true bitmap and set correct font
self.contents = Bitmap.new(width-32, @item_max*24)
self.contents.font.name = CREDITS_FONT_NAME_STANDARD
self.contents.font.size = CREDITS_FONT_SIZE_STANDARD
#process words array
@word_ary.each_index {|index|
line = @word_ary[index]
#if title marker is found, change color, font and size
if @color_ary[index]
self.contents.font.color = CREDITS_FONT_COLOR_TITLE
self.contents.font.name = CREDITS_FONT_NAME_TITLE
self.contents.font.size = CREDITS_FONT_SIZE_TITLE
else
self.contents.font.color = CREDITS_FONT_COLOR_STANDARD
self.contents.font.name = CREDITS_FONT_NAME_STANDARD
self.contents.font.size = CREDITS_FONT_SIZE_STANDARD
end
#draw line
self.contents.draw_text(4,index*(CREDITS_FONT_SIZE_STANDARD+2),self.width-32,CREDITS_FONT_SIZE_STANDARD+2,line)
}
end
#--------------------------------------------------------------------------
# * prepare_words
#--------------------------------------------------------------------------
def prepare_words
#clone lines array
ary = @word_ary.clone
#create empty array
new_ary = []
color_ary = []
#process
for i in 0...ary.size
#split line into words
line = ary[i].split(/ /)
#reset new text and color flag
text = ""
color_flag = false
#scan line
for j in 0...line.size
#check every word
word = line[j]
#if title marker is found, then set colour flag to true
word.gsub(CREDITS_TITLE_MARKER){
color_flag = true
}
word.gsub!(CREDITS_TITLE_MARKER){
CREDITS_TITLE_MARKER_SUB
}
#check size
size = self.contents.text_size(text+word).width
#if size is too large, then do a carriage return
if (size < self.width - 32)
text += word + " "
if j == line.size-1
new_ary.push(text)
color_ary.push(color_flag)
text = ""
end
else
#push text into new array
new_ary.push(text)
color_ary.push(color_flag)
text = word + " "
end
end
end
#set new arrays (ready to be employed)
@word_ary = new_ary
@color_ary = color_ary
end
#--------------------------------------------------------------------------
# * update
#--------------------------------------------------------------------------
def update
super
end
end
#==============================================================================
# ** Scene_Credits
#------------------------------------------------------------------------------
# call this scene like this:
# $scene = Scene_Credits.new
#==============================================================================
class Scene_Credits
#--------------------------------------------------------------------------
# * main
#--------------------------------------------------------------------------
def main
#set backgrounf image
@background_sprite = RPG::Sprite.new
if CREDITS_BG_PICTURE_NAME != "" and
FileTest.exist?("Graphics/Pictures/" + CREDITS_BG_PICTURE_NAME)
@background_sprite.bitmap = RPG::Cache.picture(CREDITS_BG_PICTURE_NAME)
@background_sprite.x = 320
@background_sprite.y = 240
@background_sprite.ox = @background_sprite.bitmap.width/2
@background_sprite.oy = @background_sprite.bitmap.height/2
end
Graphics.transition
#credits window
@credits_window = Window_Credits.new(CREDITS_FILE_NAME)
@credits_window.oy = -600
#transition from previous scene
#bgm play
if FileTest.exist?("Audio/BGM/" + CREDITS_BGM_NAME)
Audio.bgm_play("Audio/BGM/" + CREDITS_BGM_NAME,
CREDITS_BGM_VOLUME,
CREDITS_BGM_PITCH)
end
#loop main sequence
loop do
# graphics update
Graphics.update
# input update
Input.update
# general update
update
# break loop if scene is changed
if $scene != self
break
end
end
# freeze graphics and dispose windows&pictures
Graphics.freeze
@credits_window.dispose
if @background_sprite.bitmap != nil
@background_sprite.bitmap.dispose
end
@background_sprite.dispose
end
#--------------------------------------------------------------------------
# * update
#--------------------------------------------------------------------------
def update
#window update
@credits_window.update
#window scroll
@credits_window.oy += CREDITS_SCROLL_SPEED
#stop credits if text is over
if @credits_window.oy == @credits_window.contents.height
@vanish_time = 100
$game_system.bgm_fade(6)
end
#if vanishing, decrease opacity
if @vanish_time != nil
@vanish_time -= 1
@credits_window.contents_opacity -= 3
@background_sprite.opacity -= 3
#if opacity is zero, return to title screen
if @vanish_time <= 0
$scene = Scene_Title.new
return
end
else
#if C or B pressed, begin vanishing
if Input.press?(Input::B) or Input.press?(Input::C)
@vanish_time = 100
$game_system.bgm_fade(6)
return
end
end
end
end
CustomizationDescribed in the script itself
Compatibility Standalone script
Installation Paste it in a blank above main
Terms and Conditions Described in the script itself
To recall this script, simply call it as below:
CODE
$scene = Scene_Credits.new
Ask for troubleshooting anytime.
Jens
EDIT:Scene Credit Addon Features This script will work with the previous one, just paste it above main, but below the previous one.
It will show pictures from a folder with a gradual appear/fade effect, like a slideshow.
Terms and Conditions Same as above
Code:
CODE
#==============================================================================
#=#============================================================================
# #** Jens of Zanicuud credits picture addon script v 1.0
# # -free use, just credit
# # -free customization, however, posting on RRR the modified version is
# # mandatory
# # -you can find me on www.rpgrevolution.com
#=#============================================================================
#==============================================================================
#--------------------------------------------------------------------------
# * constants
#--------------------------------------------------------------------------
CREDIT_PICTURE_FOLDER = 'Graphics/Credits/'
CREDIT_PICTURE_DURATION = 120
CREDIT_PICTURE_FADE_TIME = 40
CREDIT_PICTURE_FIRST_LAG = 100
CREDIT_LAST_PICTURE_DURATION = 900
#==============================================================================
# ** Scene_Credits
#------------------------------------------------------------------------------
# call this scene like this:
# $scene = Scene_Credits.new
#==============================================================================
class Scene_Credits
#--------------------------------------------------------------------------
# * aliases
#--------------------------------------------------------------------------
alias joz3_credits_scene_main main
alias joz3_credits_scene_update update
#--------------------------------------------------------------------------
# * main
#--------------------------------------------------------------------------
def main
@wait_for_first_picture = CREDIT_PICTURE_FIRST_LAG
@picture_duration = CREDIT_PICTURE_DURATION
@appear_duration = CREDIT_PICTURE_FADE_TIME
@fade_duration = CREDIT_PICTURE_FADE_TIME
@gallery_sprite = RPG::Sprite.new
@gallery_index = 0
joz3_credits_scene_main
@gallery_sprite.bitmap.dispose
@gallery_sprite.dispose
end
#--------------------------------------------------------------------------
# * update
#--------------------------------------------------------------------------
def update
joz3_credits_scene_update
@wait_for_first_picture -= 1
if @wait_for_first_picture > 0
return
end
if @vanish_time != nil
@gallery_sprite.opacity -= 3
else
#create photo
if @appear_duration == CREDIT_PICTURE_FADE_TIME
filename = CREDIT_PICTURE_FOLDER + @gallery_index.to_s + ".png"
if FileTest.exist?(filename)
filename = @gallery_index.to_s + ".png"
@gallery_sprite.bitmap = RPG::Cache.load_bitmap(CREDIT_PICTURE_FOLDER,filename,0)
@gallery_sprite.x = 320
@gallery_sprite.y = 240
@gallery_sprite.ox = @gallery_sprite.bitmap.width/2
@gallery_sprite.oy = @gallery_sprite.bitmap.height/2
@gallery_sprite.opacity = 0
@gallery_index += 1
filename = CREDIT_PICTURE_FOLDER + @gallery_index.to_s + ".png"
if !FileTest.exist?(filename)
@picture_duration = CREDIT_LAST_PICTURE_DURATION
else
@picture_duration = CREDIT_PICTURE_DURATION
end
@fade_duration = CREDIT_PICTURE_FADE_TIME
@appear_duration -= 1
else
@fade_duration = 0
@appear_duration = 0
@wait_for_first_picture = 0
end
return
end
#photo appear
if @appear_duration > 0
@appear_duration -= 1
@gallery_sprite.opacity += [255/CREDIT_PICTURE_FADE_TIME.to_f,1].max
return
end
#photo mantain
if @picture_duration > 0
@picture_duration -= 1
return
end
#photo fade
if @fade_duration > 0
@fade_duration -= 1
@gallery_sprite.opacity -= [255/CREDIT_PICTURE_FADE_TIME.to_f,1].max
return
end
#photo reset
if @fade_duration <= 0
@appear_duration = CREDIT_PICTURE_FADE_TIME
@wait_for_first_picture = CREDIT_PICTURE_FIRST_LAG
end
end
end
end
CustomizationScript customization is tied to these constants:
CODE
CREDIT_PICTURE_FOLDER = 'Graphics/Credits/'
CREDIT_PICTURE_DURATION = 120
CREDIT_PICTURE_FADE_TIME = 40
CREDIT_PICTURE_FIRST_LAG = 100
CREDIT_LAST_PICTURE_DURATION = 900
>CREDIT_PICTURE_FOLDER
The first one is the name of the folder in which you have saved the picture you wanna display.
These pictures should be called 0.png, 1.png, 2.png and so on.
The script will play these pictures from 0 to the last one present in your folder. Note that if there are holes (e.g. 1.png, 3.png, 4.png...)
the script will stop playing. Be sure you have all the pictures needed.
>CREDIT_PICTURE_DURATION
Duration of every picture
>CREDIT_PICTURE_FADE_TIME
Amount of frames in which pictures will appear/fade
>CREDIT_PICTURE_FIRST_LAG
Frames interval between pictures
>CREDIT_LAST_PICTURE_DURATION
Last picture duration can be set here
Jens
This post has been edited by Jens of Zanicuud: Feb 24 2012, 06:57 AM