Yes, more math problems. But this time I think I've improved the way I ask for help.
I've been trying to create a clipping method for a sprite reflection script for a very long time, but the math always seems to be beyond me.
The method would set the rect of a sprite based on the distance between Point A and B, this effect would make it seem like the reflection of the sprite is being cut off as it exits a reflective area into a non reflective area.
For example if a sprite moves from point A (0) to B (32) in 16 frames then it would be moving at 2 pixels per frame (2 * 16 = 32) and it would clip the sprites accordingly based on it's direction. Let's say it's clipping by X and the sprite's width is 64, it would cut 4 pixels from the sprites width per frame until it disappears (4 * 16 = 64).
In theory I think I have it down... But in practice it's another breed of cat all together.
I would like some help in figuring out how to obtain a proper value to use for the distance between a current position and a new one of a moving character. I've spent a long time reading the character scripts and methods and I know exponents are involved, but following the values gives me very mixed results and when I think I've found a good formula changing the speed of the character messes it up.
I'm sure it's probably something simple, but I've been working on this for so long I'm probably blind to the answer by now.
Here's the script I'm working on [VX Ace].
#==============================================================================
# ** TDS Sprite Reflection
# Ver: 1.0
#------------------------------------------------------------------------------
# * Description:
#
#------------------------------------------------------------------------------
# * Features:
#
#------------------------------------------------------------------------------
# * Instructions:
#
#------------------------------------------------------------------------------
# * Notes:
# None.
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
# way from the consequenses.
#==============================================================================
# * Import to Global Hash *
#==============================================================================
($imported ||= {})[:TDS_Sprite_Reflection] = true
#------------------------------------------------------------------------------
# * Constants
#------------------------------------------------------------------------------
# Reflection Terrain Tag ID
REFLECTION_TERRAIN_TAG = 1
# Reflection Water Wave Effect
REFLECTION_WAVE_EFFECT = true
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias tds_sprite_reflection_spriteset_map_initialize initialize
alias tds_sprite_reflection_spriteset_map_dispose dispose
alias tds_sprite_reflection_spriteset_map_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Create Character Reflection Sprites
create_character_reflections
# Run Original Method
tds_sprite_reflection_spriteset_map_initialize
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
# Run Original Method
tds_sprite_reflection_spriteset_map_dispose
# Dispose of Reflection Sprites
@reflection_sprites.each {|s| s.dispose}
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Run Original Method
tds_sprite_reflection_spriteset_map_update
# Update Character Reflections
update_character_reflections
end
#--------------------------------------------------------------------------
# * Create Character Reflection Sprites
#--------------------------------------------------------------------------
def create_character_reflections
# Make Reflection Sprites Array
@reflection_sprites = []
# Go Through Game Map Events
$game_map.events.values.each do |event|
# If Event has Reflection
if event.has_reflection?
# Add Reflection Sprite to Array
@reflection_sprites << Sprite_Character_Reflection.new(@viewport1, event)
end
end
# Go Through Follower Sprites
$game_player.followers.reverse_each do |follower|
# Add Reflection Sprite to Array
@reflection_sprites << Sprite_Character_Reflection.new(@viewport1, follower)
end
# Add Player Reflection Sprite to Array
@reflection_sprites << Sprite_Character_Reflection.new(@viewport1, $game_player)
end
#--------------------------------------------------------------------------
# * Update Character Reflection Sprites
#--------------------------------------------------------------------------
def update_character_reflections
# Update Reflection Sprites
@reflection_sprites.each {|s| s.update}
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# A character class with mainly movement route and other such processing added.
# It is used as a super class of Game_Player, Game_Follower, GameVehicle,
# and Game_Event.
#==============================================================================
class Game_Character < Game_CharacterBase
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :reflection_active # Reflection Active Flag
attr_accessor :reflection_visible # Reflection Visiblity Flag
attr_accessor :reflection_y_offset # Reflection Y Offset value
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias tds_sprite_reflection_game_character_init_public_members init_public_members
#--------------------------------------------------------------------------
# * Initialize Public Member Variables
#--------------------------------------------------------------------------
def init_public_members
# Set Reflection Active Flag
@reflection_active = true
# Set Reflection Visibility Flag
@reflection_visible = true
# Set Reflection Y Offset Value
@reflection_y_offset = 9
# Run Original Method
tds_sprite_reflection_game_character_init_public_members
end
#--------------------------------------------------------------------------
# * Determine if Character has a reflection
#--------------------------------------------------------------------------
def has_reflection?
# If Self is an Game_Event Character
if self.is_a?(Game_Event)
# Return true if Event Name Includes the Reflect Flag
return true if /\[REFLECT\]/i =~ @event.name
end
# Return false by default
return false
end
#--------------------------------------------------------------------------
# * Determine if Character reflection is visible
#--------------------------------------------------------------------------
def reflection_visible?
return false if !@reflection_active
return false if @transparent
return false if $game_map.terrain_tag(@x, @y + 1) != REFLECTION_TERRAIN_TAG
return true
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display character reflection. It observes an instance
# of the Game_Character class and automatically changes sprite state.
#==============================================================================
class Sprite_Character_Reflection < Sprite_Character
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# character : Game_Character
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport, character)
# Character Ojbect
@character = character
# Reflection Sprite Settings
self.mirror = true ; self.angle = 180 ; self.opacity = 160
# Set Self Wave Amp if Reflection Wave Effect is true
self.wave_amp = 1 if REFLECTION_WAVE_EFFECT
# Update
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose ; super end ; def update_balloon ; end ; def setup_new_effect ; end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
end
#--------------------------------------------------------------------------
# * Update Transfer Origin Rectangle
#--------------------------------------------------------------------------
def update_src_rect
# FOR CLIPPING TESTING
if @character.moving? and (self.visible and !@character.reflection_visible?)
# CLIP HERE
return
end
super
end
#--------------------------------------------------------------------------
# * Update Position
#--------------------------------------------------------------------------
def update_position
self.x = @character.screen_x
self.y = @character.screen_y + @character.reflection_y_offset
self.z = @character.screen_z
end
#--------------------------------------------------------------------------
# * Update Other
#--------------------------------------------------------------------------
def update_other
self.blend_type = @character.blend_type
# self.visible = @visible = @character.reflection_visible?
end
end
If I need to explain myself more clearly, please let me know.
Thank you for reading and have a nice day.