Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # *****************************************************************************
- #
- # OC ANIMATED TITLE SCREEN
- # Author: Ocedic
- # Site: http://ocedic.wordpress.com/
- # Version: 1.0
- # Last Updated: 3/16/13
- #
- # Updates:
- # 1.0 - First release
- #
- # *****************************************************************************
- $imported = {} if $imported.nil?
- $imported["OC-AnimatedTitleLayers"] = true
- #==============================================================================
- # ▼ Introduction
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # This script allows you to create a custom title screen with moving, animated
- # layers.
- #==============================================================================
- # ▼ Instructions
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Place this script above Main and customize options in the configuration
- # section. Files must be have a "-x" after their name, where x is their frame
- # number. For example, if you have a layer called "dog.png" with 3 frames of
- # animation, each file must be named "dog-1.png", "dog-2.png" and "dog-3.png"
- # respectively. Since all layers have at least one frame, even if you aren't
- # using animation for that layer the file must have a "-1" after it.
- #
- # See demo for further
- #==============================================================================
- # ▼ Compatibility
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # This script may not be compatible with other scripts that affect the title
- # scene.
- #==============================================================================
- # ▼ Terms of Use
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Can be freely used and modified in non-commercial projects. Proper attribution
- # must be given to Ocedic, and this header must be preserved.
- # For commercial terms, see here: https://ocedic.wordpress.com/terms-of-use/
- #==============================================================================
- #==============================================================================
- # ■ Configuration
- #------------------------------------------------------------------------------
- # Change customizable settings here
- #==============================================================================
- module OC
- module TITLE
- #==============================================================================
- # * Layers Path *
- #------------------------------------------------------------------------------
- # The folder in which custom layers are stored.
- #==============================================================================
- LAYERS_PATH = "Graphics/TitleLayers/"
- #==============================================================================
- # * Layer Speed *
- #------------------------------------------------------------------------------
- # The speed at which the layers will move into position.
- #==============================================================================
- # * Update Frequency *
- #------------------------------------------------------------------------------
- # How often the layers will update position and zoom. This variable is an
- # update every x frames. This means that a higher number will slow the speed.
- #==============================================================================
- # * Focus Zoom *
- #------------------------------------------------------------------------------
- # The amount of zoom on the focus entry. A higher number is greater zoom.
- #==============================================================================
- # * Zoom Speed *
- #------------------------------------------------------------------------------
- # The speed at which the focus entry zooms in. Recommended to keep it at a
- # multiple of 0.004. A higher number is higher zoom speed.
- #==============================================================================
- LAYER_SPEED = 2 # Default 2
- UPDATE_FREQ = 2 # Default 2
- FOCUS_ZOOM = 1.3 # Default 1.3
- ZOOM_SPEED = 0.004 # Default 0.004
- #==============================================================================
- # * Title Layers *
- #------------------------------------------------------------------------------
- # Manage all of your layers in this array. To add a new layer, copy one of
- # the elements. "Filename" is the name of the graphic file.
- # "Z-index" is how it will be displayed relative to other layers. The higher
- # the z-index, the closer to the foreground it is.
- # "Position" is the final x and y coordinates of the image.
- # "Frames" is the number of frames of animation for the layer. For file naming
- # instructions, see above.
- # "Refresh" is the refresh rate of the layer. A lower number gives a faster
- # animation.
- # "Blend" is the blending mode that the bitmap will use. 0 is normal, 1 is
- # additive, 2 is subtractive.
- # "Entry" is the type of entry effect the layer uses. There are a number of
- # pre-defined entries:
- # :origin - The layer appears as is at the position
- # :focus - The layer zooms in by the focus zoom above
- # :left - The layer comes in from the left and moves to position
- # :right - The layer comes in from the right and moves to position
- #
- #==============================================================================
- LAYERS = [
- # ["filename", z-index, position, entry, frames, refresh, blend],
- ["mansion", 0, 0,0, :focus, 1, 0, 0],
- ["gatel", 5, -50,40, :left, 4, 10, 0],
- ["gater", 10, 50,40, :right, 1, 0, 0],
- ["smoke", 15, 0,-60, :bottom, 4, 5, 0],
- ] # Don't delete this
- end #TITLE
- end #OC
- #==============================================================================
- # ■ End of Configuration
- #==============================================================================
- #==============================================================================
- # ■ New Class: Sprite_Layer
- #==============================================================================
- class Sprite_Layer < Sprite_Base
- #==============================================================================
- # * Accessors *
- #==============================================================================
- attr_accessor :target_x
- attr_accessor :target_y
- attr_accessor :filename
- attr_accessor :frames
- attr_accessor :refresh
- #==============================================================================
- # * Alias: Initialize *
- #==============================================================================
- alias oc_sprite_layer_initialize_2nols initialize
- def initialize(viewport = nil)
- oc_sprite_layer_initialize_2nols
- @filename = nil
- @frames = 0
- @refresh = 0
- @target_x = 0
- @target_y = 0
- @target_zoom = 1.0
- @entry = nil
- @current_frame = 1 # Current frame of animation loaded
- end
- #==============================================================================
- # * New Method: Set Initial Position *
- #==============================================================================
- def set_initial_pos(entry)
- case entry
- when :origin
- self.x = @target_x
- self.y = @target_y
- @entry = :origin
- when :focus
- @target_zoom = OC::TITLE::FOCUS_ZOOM
- @entry = :focus
- when :left
- self.x = -Graphics.width / 3
- self.y = @target_y
- @entry = :left
- when :right
- self.x = Graphics.width / 3
- self.y = @target_y
- @entry = :right
- when :top
- self.x = @target_x
- self.y = -Graphics.height / 3
- @entry = :top
- when :bottom
- self.x = @target_x
- self.y = Graphics.height / 3
- @entry = :bottom
- end
- end
- #==============================================================================
- # * New Method: Change Frame *
- #==============================================================================
- def change_frame(id)
- filename = @filename + "-" + id.to_s
- self.bitmap = Cache.load_bitmap(OC::TITLE::LAYERS_PATH, filename)
- end
- #==============================================================================
- # * New Method: Update Layer *
- #==============================================================================
- def update_layer
- @update_timer ||= 0
- @update_timer += 1
- update_position if @update_timer % OC::TITLE::UPDATE_FREQ == 0 &&
- ((((self.x != @target_x) || (self.y != @target_y)) &&
- @entry != :focus) || (self.zoom_x != @target_zoom))
- @update_refresh ||= 0
- @update_refresh += 1
- update_animation if @frames > 1 && @update_refresh % @refresh == 0
- end
- #==============================================================================
- # * New Method: Update Position *
- #==============================================================================
- def update_position
- case @entry
- when :focus
- self.zoom_x += [OC::TITLE::ZOOM_SPEED, @target_zoom - self.zoom_x].min
- self.zoom_y += [OC::TITLE::ZOOM_SPEED, @target_zoom - self.zoom_y].min
- self.x -= OC::TITLE::ZOOM_SPEED / 0.004
- self.y -= OC::TITLE::ZOOM_SPEED / 0.004
- when :left
- self.x += [OC::TITLE::LAYER_SPEED, @target_x - x].min
- when :right
- self.x -= [OC::TITLE::LAYER_SPEED, x - @target_x].min
- when :top
- self.y += [OC::TITLE::LAYER_SPEED, @target_y - y].min
- when :bottom
- self.y -= [OC::TITLE::LAYER_SPEED, y - @target_y].min
- end
- end
- #==============================================================================
- # * New Method: Update Animation *
- #==============================================================================
- def update_animation
- if @current_frame < @frames
- @current_frame += 1
- else
- @current_frame = 1
- end
- change_frame(@current_frame)
- end
- end #class sprite_layer
- #==============================================================================
- # ■ Scene_Title
- #==============================================================================
- class Scene_Title < Scene_Base
- #==============================================================================
- # * Overwrite: Start *
- #==============================================================================
- def start
- super
- SceneManager.clear
- Graphics.freeze
- @layers = Array.new
- @fogs = Array.new
- load_layers
- create_command_window
- play_title_music
- end
- #==============================================================================
- # * Overwrite: Update Basic *
- #==============================================================================
- def update_basic
- super
- @layers.each do |layer|
- layer.update_layer
- end
- end
- #==============================================================================
- # * New Method: Load Layers *
- #------------------------------------------------------------------------------
- # Loads all layers defined in the LAYERS array into an array of sprite layers
- # that we can manage and manipulate
- #==============================================================================
- def load_layers
- i = 0
- OC::TITLE::LAYERS.each do |layer|
- @layers << Sprite_Layer.new
- @layers[i].filename = layer[0]
- @layers[i].frames = layer[5]
- @layers[i].refresh = layer[6]
- filename = layer[0] + "-1"
- @layers[i].bitmap = Cache.load_bitmap(OC::TITLE::LAYERS_PATH, filename)
- @layers[i].blend_type = layer[7]
- @layers[i].z = layer[1]
- @layers[i].target_x = layer[2]
- @layers[i].target_y = layer[3]
- @layers[i].set_initial_pos(layer[4])
- i += 1
- end
- end
- #==============================================================================
- # * Overwrite: Terminate *
- #==============================================================================
- def terminate
- super
- SceneManager.snapshot_for_background
- @layers.each do |layer|
- layer.dispose
- end
- end
- end #class scene_title
Advertisement
Add Comment
Please, Sign In to add comment