Hey, while back Sephiroth gave me a script that places circles of light around the player and events when all the lights go out. I know how to do this with a pic placed ofer the screen, but I also want it around key events (such as torches, fires, lanterns, etc)
I have the script, but it is very laggy if there is more than 2 or 3 circles in the map, or if the circles are too big.
I love the script, I use it a lot, but I would like to know if there is anything that anyone (mainly seph) could do to improve the framerate, and possibly instead of a hard edge for the circle (ie, it does not fade to black, it is a hard edge) make it fade out around the edges a little.
You (seph) said that you would try it a while ago, and possibly use an pic instead of making the circle in the script.
Is there an update on this? If not then I will request one please.
If you need the script, here it is...
Thanks
Kraft
I have the script, but it is very laggy if there is more than 2 or 3 circles in the map, or if the circles are too big.
I love the script, I use it a lot, but I would like to know if there is anything that anyone (mainly seph) could do to improve the framerate, and possibly instead of a hard edge for the circle (ie, it does not fade to black, it is a hard edge) make it fade out around the edges a little.
You (seph) said that you would try it a while ago, and possibly use an pic instead of making the circle in the script.
Is there an update on this? If not then I will request one please.
If you need the script, here it is...
#==============================================================================
# ** Bitmap
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# * Draw Circle
#--------------------------------------------------------------------------
def draw_circle(x, y, radius, color = Color.new(255, 255, 255, 255))
# Starts From Left
for i in (x - radius)..(x + radius)
# Finds Distance From Center
sa = (x - i).abs
# Finds X Position
x_ = i < x ? x - sa : i == x ? x : x + sa
# Finds Top Vertical Portion
y_ = Integer((radius ** 2 - sa ** 2) ** 0.5)
# Draws Vertical Bar
self.fill_rect(x_, y - y_, 1, y_ * 2, color)
end
end
end
#==============================================================================
# ** Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :circle_of_light_on
attr_accessor :circle_of_light_opacity
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_gamesys_init initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_gamesys_init
# Turns On Defaults
@circle_of_light_on = false
@circle_of_light_opacity = 225
end
end
#==============================================================================
# ** Game_Player
#==============================================================================
class Game_Player
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :circle_of_light_on
attr_accessor :circle_of_light_radius
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_gameplyr_init initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_gameplyr_init
# Turns On Defaults
@circle_of_light_on = true
@circle_of_light_radius = 60
end
end
#==============================================================================
# ** Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_ssmap_init initialize
alias seph_col_ssmap_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_ssmap_init
# Creates Circle Of Light Sprite
@circle_of_light_sprite = Sprite.new
@circle_of_light_sprite.bitmap = Bitmap.new(640, 480)
@circle_of_light_locations = {}
# Update
update
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Original Initialization
seph_col_ssmap_update
# Stop If no Circle Of Light Sprite
unless @circle_of_light_sprite.nil?
# Update Visibilty
@circle_of_light_sprite.visible = $game_system.circle_of_light_on
# If Sprite Visible
if @circle_of_light_sprite.visible
# Update Circle Of Light
seph_col_updatecircleoflight
end
end
end
#--------------------------------------------------------------------------
# * Redraw Player Test
#--------------------------------------------------------------------------
def seph_col_redrawplayertest
# Test For Player Redraw
if $game_player.circle_of_light_on
# If Light Locations Don't Include Player
unless @circle_of_light_locations.has_key?(0)
# Returns Redraw
return true
# If Light Locations Include Player
else
# If Player Location Same
if @circle_of_light_locations[0][0] != $game_player.screen_x ||
@circle_of_light_locations[0][1] != $game_player.screen_y
# Returns Redraw
return true
end
end
end
# Returns Dont Redraw
return seph_col_redraweventstest
end
#--------------------------------------------------------------------------
# * Redraw Events Test
#--------------------------------------------------------------------------
def seph_col_redraweventstest
# Check All Events
$game_map.events.keys.each do |event_id|
# Returns Redraw If Need to Redraw Event
return true if seph_col_redraweventtest(event_id)
end
# Returns Dont Redraw
return false
end
#--------------------------------------------------------------------------
# * Redraw Event Test
#--------------------------------------------------------------------------
def seph_col_redraweventtest(event_id)
# Get Event Data
event = $game_map.events[event_id]
# Return if no List
return if event.list.nil?
# Checks All Event Commands
for i in 0...event.list.size
# Check For Comment Command
if event.list.code == 108
# Check For Circle of Light Comment
if event.list.parameters[0].include?('Circle Of Light')
# If Light Locations Dosen't Include Event
unless @circle_of_light_locations.has_key?(event_id)
# Returns Redraw
return true
# If Light Locations Include Event
else
# If Event Location Different
if @circle_of_light_locations[event_id][0] != event.screen_x ||
@circle_of_light_locations[event_id][1] != event.screen_y
# Returns Redraw
return true
end
end
end
end
end
# Returns Don't Redraw
return false
end
#--------------------------------------------------------------------------
# * Frame Update : Circle Of Light
#--------------------------------------------------------------------------
def seph_col_updatecircleoflight
# Stop If Not Redrawing Player or Event Circles
return unless seph_col_redrawplayertest
# Redraw Sprite Cover
color = Color.new(0, 0, 0, $game_system.circle_of_light_opacity)
@circle_of_light_sprite.bitmap.fill_rect(0, 0, 640, 480, color)
# Circle Color
circle_color = Color.new(0, 0, 0, 0)
# Redraw Player Circles
if seph_col_redrawplayertest
# Player Circle Center & Radius
x = $game_player.screen_x
y = $game_player.screen_y
r = $game_player.circle_of_light_radius
# Store X & Y Coordinates
@circle_of_light_locations[0] = [x, y]
@circle_of_light_sprite.bitmap.draw_circle(x, y - 32, r, circle_color)
# Redraw Event Circles
# Checks All Events
$game_map.events.each do |event_id, event|
# Next if nil list
next if event.list.nil?
# Checks All Event Commands
for i in 0...event.list.size
# Check For Comment Command
if event.list.code == 108
# Check For Circle of Light Comment
if event.list.parameters[0].include?('Circle Of Light')
event.list.parameters[0].dup.gsub(/(\d+)/, '')
# Collects Circle Center & Redius
x = event.screen_x
y = event.screen_y
r = $1.to_i
# Store Event Circle X & Y
@circle_of_light_locations[event_id] = [x, y]
# Draw Circle
@circle_of_light_sprite.bitmap.draw_circle(x, y - 16, r, circle_color)
end
end
end
end
end
end
end
# ** Bitmap
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# * Draw Circle
#--------------------------------------------------------------------------
def draw_circle(x, y, radius, color = Color.new(255, 255, 255, 255))
# Starts From Left
for i in (x - radius)..(x + radius)
# Finds Distance From Center
sa = (x - i).abs
# Finds X Position
x_ = i < x ? x - sa : i == x ? x : x + sa
# Finds Top Vertical Portion
y_ = Integer((radius ** 2 - sa ** 2) ** 0.5)
# Draws Vertical Bar
self.fill_rect(x_, y - y_, 1, y_ * 2, color)
end
end
end
#==============================================================================
# ** Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :circle_of_light_on
attr_accessor :circle_of_light_opacity
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_gamesys_init initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_gamesys_init
# Turns On Defaults
@circle_of_light_on = false
@circle_of_light_opacity = 225
end
end
#==============================================================================
# ** Game_Player
#==============================================================================
class Game_Player
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :circle_of_light_on
attr_accessor :circle_of_light_radius
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_gameplyr_init initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_gameplyr_init
# Turns On Defaults
@circle_of_light_on = true
@circle_of_light_radius = 60
end
end
#==============================================================================
# ** Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_col_ssmap_init initialize
alias seph_col_ssmap_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_col_ssmap_init
# Creates Circle Of Light Sprite
@circle_of_light_sprite = Sprite.new
@circle_of_light_sprite.bitmap = Bitmap.new(640, 480)
@circle_of_light_locations = {}
# Update
update
end
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
def update
# Original Initialization
seph_col_ssmap_update
# Stop If no Circle Of Light Sprite
unless @circle_of_light_sprite.nil?
# Update Visibilty
@circle_of_light_sprite.visible = $game_system.circle_of_light_on
# If Sprite Visible
if @circle_of_light_sprite.visible
# Update Circle Of Light
seph_col_updatecircleoflight
end
end
end
#--------------------------------------------------------------------------
# * Redraw Player Test
#--------------------------------------------------------------------------
def seph_col_redrawplayertest
# Test For Player Redraw
if $game_player.circle_of_light_on
# If Light Locations Don't Include Player
unless @circle_of_light_locations.has_key?(0)
# Returns Redraw
return true
# If Light Locations Include Player
else
# If Player Location Same
if @circle_of_light_locations[0][0] != $game_player.screen_x ||
@circle_of_light_locations[0][1] != $game_player.screen_y
# Returns Redraw
return true
end
end
end
# Returns Dont Redraw
return seph_col_redraweventstest
end
#--------------------------------------------------------------------------
# * Redraw Events Test
#--------------------------------------------------------------------------
def seph_col_redraweventstest
# Check All Events
$game_map.events.keys.each do |event_id|
# Returns Redraw If Need to Redraw Event
return true if seph_col_redraweventtest(event_id)
end
# Returns Dont Redraw
return false
end
#--------------------------------------------------------------------------
# * Redraw Event Test
#--------------------------------------------------------------------------
def seph_col_redraweventtest(event_id)
# Get Event Data
event = $game_map.events[event_id]
# Return if no List
return if event.list.nil?
# Checks All Event Commands
for i in 0...event.list.size
# Check For Comment Command
if event.list.code == 108
# Check For Circle of Light Comment
if event.list.parameters[0].include?('Circle Of Light')
# If Light Locations Dosen't Include Event
unless @circle_of_light_locations.has_key?(event_id)
# Returns Redraw
return true
# If Light Locations Include Event
else
# If Event Location Different
if @circle_of_light_locations[event_id][0] != event.screen_x ||
@circle_of_light_locations[event_id][1] != event.screen_y
# Returns Redraw
return true
end
end
end
end
end
# Returns Don't Redraw
return false
end
#--------------------------------------------------------------------------
# * Frame Update : Circle Of Light
#--------------------------------------------------------------------------
def seph_col_updatecircleoflight
# Stop If Not Redrawing Player or Event Circles
return unless seph_col_redrawplayertest
# Redraw Sprite Cover
color = Color.new(0, 0, 0, $game_system.circle_of_light_opacity)
@circle_of_light_sprite.bitmap.fill_rect(0, 0, 640, 480, color)
# Circle Color
circle_color = Color.new(0, 0, 0, 0)
# Redraw Player Circles
if seph_col_redrawplayertest
# Player Circle Center & Radius
x = $game_player.screen_x
y = $game_player.screen_y
r = $game_player.circle_of_light_radius
# Store X & Y Coordinates
@circle_of_light_locations[0] = [x, y]
@circle_of_light_sprite.bitmap.draw_circle(x, y - 32, r, circle_color)
# Redraw Event Circles
# Checks All Events
$game_map.events.each do |event_id, event|
# Next if nil list
next if event.list.nil?
# Checks All Event Commands
for i in 0...event.list.size
# Check For Comment Command
if event.list.code == 108
# Check For Circle of Light Comment
if event.list.parameters[0].include?('Circle Of Light')
event.list.parameters[0].dup.gsub(/(\d+)/, '')
# Collects Circle Center & Redius
x = event.screen_x
y = event.screen_y
r = $1.to_i
# Store Event Circle X & Y
@circle_of_light_locations[event_id] = [x, y]
# Draw Circle
@circle_of_light_sprite.bitmap.draw_circle(x, y - 16, r, circle_color)
end
end
end
end
end
end
end
Thanks
Kraft