|
  |
RMXP animations available for use by script V2.6, Animator2.6 has rolled out of the factory with multi weather driving |
|
|
|
|
Jun 30 2008, 10:33 PM
|

Level 3

Group: Member
Posts: 41
Type: Scripter
RM Skill: Skilled

|
~edit Animator 2.6 has now been posted, please see reply #3 aka post#4 ~~~~~~~~~~~~~~~~outdated~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I don't know if such a script has been posted before, but here is a class which i've called Ani (short for animation) which if you insert a call to it using the below command Ani.new.mio( animation_id, x_coordinate, y_coordinate)anywhere in a script, like in an event script box, or even in a title screen or anywhere -- very useful in handmade scenes(that is, if I ever get it to work properly with non map scenes) the animation will be displayed at the coordinates given. Right now if it is called, it will run in its own little loop, so everything else will be paused until the animation ends. But the animations are fast anyway, so who'd notice? warning The full screen animations like the fire3 seem to have a glitch. they leave the screen colored for a couple seconds after the animation is done. But none the less this is an awsome ability to use the animations provided or make your own for hand crafted scenes. This requires two scripts. The RPG::Sprite,SpriteAnimation script found in PB pokemon game from pokemon community forum and my Ani class script, which is a reversed engineered version of the SpriteCharacter and RPG::Sprite scripts. Feel free to usemy Ani class at whim, no credit needed, even for commercial games. Though you will need to give credit to pokemon comm for their written out RPG::Sprite class andSpriteAnimation class. instructions: 1) copy the RPG::Sprite,SpriteAnimation script and paste it above all your other scripts. CODE class SpriteAnimation @@_animations = [] @@_reference_count = {} def initialize(sprite) @sprite=sprite end %w[ x y ox oy viewport flash src_rect opacity ].each_with_index do |s, i| eval <<-__END__ def #{s}(*arg) @sprite.#{s}(*arg) end __END__ end def self.clear @@_animations.clear end def dispose dispose_animation dispose_loop_animation end def animation(animation, hit) dispose_animation @_animation = animation return if @_animation == nil @_animation_hit = hit @_animation_duration = @_animation.frame_max animation_name = @_animation.animation_name animation_hue = @_animation.animation_hue bitmap = RPG::Cache.animation(animation_name, animation_hue) if @@_reference_count.include?(bitmap) @@_reference_count[bitmap] += 1 else @@_reference_count[bitmap] = 1 end @_animation_sprites = [] if @_animation.position != 3 or not @@_animations.include?(animation) for i in 0..15 sprite = ::Sprite.new(self.viewport) sprite.bitmap = bitmap sprite.visible = false @_animation_sprites.push(sprite) end unless @@_animations.include?(animation) @@_animations.push(animation) end end update_animation end def loop_animation(animation) return if animation == @_loop_animation dispose_loop_animation @_loop_animation = animation return if @_loop_animation == nil @_loop_animation_index = 0 animation_name = @_loop_animation.animation_name animation_hue = @_loop_animation.animation_hue bitmap = RPG::Cache.animation(animation_name, animation_hue) if @@_reference_count.include?(bitmap) @@_reference_count[bitmap] += 1 else @@_reference_count[bitmap] = 1 end @_loop_animation_sprites = [] for i in 0..15 sprite = ::Sprite.new(self.viewport) sprite.bitmap = bitmap sprite.visible = false @_loop_animation_sprites.push(sprite) end update_loop_animation end def dispose_animation if @_animation_sprites != nil sprite = @_animation_sprites[0] if sprite != nil @@_reference_count[sprite.bitmap] -= 1 if @@_reference_count[sprite.bitmap] == 0 sprite.bitmap.dispose end end for sprite in @_animation_sprites sprite.dispose end @_animation_sprites = nil @_animation = nil end end def dispose_loop_animation if @_loop_animation_sprites != nil sprite = @_loop_animation_sprites[0] if sprite != nil @@_reference_count[sprite.bitmap] -= 1 if @@_reference_count[sprite.bitmap] == 0 sprite.bitmap.dispose end end for sprite in @_loop_animation_sprites sprite.dispose end @_loop_animation_sprites = nil @_loop_animation = nil end end def active? @_loop_animation_sprites != nil || @_animation_sprites != nil end def effect? @_animation_duration > 0 end def update if @_animation != nil and (Graphics.frame_count % 2 == 0) @_animation_duration -= 1 update_animation end if @_loop_animation != nil and (Graphics.frame_count % 2 == 0) update_loop_animation @_loop_animation_index += 1 @_loop_animation_index %= @_loop_animation.frame_max end end def update_animation if @_animation_duration > 0 frame_index = @_animation.frame_max - @_animation_duration cell_data = @_animation.frames[frame_index].cell_data position = @_animation.position animation_set_sprites(@_animation_sprites, cell_data, position) for timing in @_animation.timings if timing.frame == frame_index animation_process_timing(timing, @_animation_hit) end end else dispose_animation end end def update_loop_animation frame_index = @_loop_animation_index cell_data = @_loop_animation.frames[frame_index].cell_data position = @_loop_animation.position animation_set_sprites(@_loop_animation_sprites, cell_data, position) for timing in @_loop_animation.timings if timing.frame == frame_index animation_process_timing(timing, true) end end end def animation_set_sprites(sprites, cell_data, position) for i in 0..15 sprite = sprites[i] pattern = cell_data[i, 0] if sprite == nil or pattern == nil or pattern == -1 sprite.visible = false if sprite != nil next end sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192) if position == 3 if self.viewport != nil sprite.x = self.viewport.rect.width / 2 sprite.y = self.viewport.rect.height - 160 else sprite.x = 320 sprite.y = 240 end else sprite.x = self.x - self.ox + self.src_rect.width / 2 sprite.y = self.y - self.oy + self.src_rect.height / 2 sprite.y -= self.src_rect.height / 4 if position == 0 sprite.y += self.src_rect.height / 4 if position == 2 end sprite.x += cell_data[i, 1] sprite.y += cell_data[i, 2] sprite.z = 2000 sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data[i, 3] / 100.0 sprite.zoom_y = cell_data[i, 3] / 100.0 sprite.angle = cell_data[i, 4] sprite.mirror = (cell_data[i, 5] == 1) sprite.opacity = cell_data[i, 6] * self.opacity / 255.0 sprite.blend_type = cell_data[i, 7] end end def animation_process_timing(timing, hit) if (timing.condition == 0) or (timing.condition == 1 and hit == true) or (timing.condition == 2 and hit == false) if timing.se.name != "" se = timing.se Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch) end case timing.flash_scope when 1 self.flash(timing.flash_color, timing.flash_duration * 2) when 2 if self.viewport != nil self.viewport.flash(timing.flash_color, timing.flash_duration * 2) end when 3 self.flash(nil, timing.flash_duration * 2) end end end def x=(x) sx = x - self.x if sx != 0 if @_animation_sprites != nil for i in 0..15 @_animation_sprites[i].x += sx end end if @_loop_animation_sprites != nil for i in 0..15 @_loop_animation_sprites[i].x += sx end end end end def y=(y) sy = y - self.y if sy != 0 if @_animation_sprites != nil for i in 0..15 @_animation_sprites[i].y += sy end end if @_loop_animation_sprites != nil for i in 0..15 @_loop_animation_sprites[i].y += sy end end end end end
module RPG class Sprite < ::Sprite def initialize(viewport = nil) super(viewport) @_whiten_duration = 0 @_appear_duration = 0 @_escape_duration = 0 @_collapse_duration = 0 @_damage_duration = 0 @_animation_duration = 0 @_blink = false @animations=[] @loopAnimations=[] end def dispose dispose_damage dispose_animation dispose_loop_animation super end def whiten self.blend_type = 0 self.color.set(255, 255, 255, 128) self.opacity = 255 @_whiten_duration = 16 @_appear_duration = 0 @_escape_duration = 0 @_collapse_duration = 0 end def appear self.blend_type = 0 self.color.set(0, 0, 0, 0) self.opacity = 0 @_appear_duration = 16 @_whiten_duration = 0 @_escape_duration = 0 @_collapse_duration = 0 end def escape self.blend_type = 0 self.color.set(0, 0, 0, 0) self.opacity = 255 @_escape_duration = 32 @_whiten_duration = 0 @_appear_duration = 0 @_collapse_duration = 0 end def collapse self.blend_type = 1 self.color.set(255, 64, 64, 255) self.opacity = 255 @_collapse_duration = 48 @_whiten_duration = 0 @_appear_duration = 0 @_escape_duration = 0 end def damage(value, critical) dispose_damage if value.is_a?(Numeric) damage_string = value.abs.to_s else damage_string = value.to_s end bitmap = Bitmap.new(160, 48) bitmap.font.name = "Arial Black" bitmap.font.size = 32 bitmap.font.color.set(0, 0, 0) bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1) bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1) bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1) bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1) if value.is_a?(Numeric) and value < 0 bitmap.font.color.set(176, 255, 144) else bitmap.font.color.set(255, 255, 255) end bitmap.draw_text(0, 12, 160, 36, damage_string, 1) if critical bitmap.font.size = 20 bitmap.font.color.set(0, 0, 0) bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1) bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1) bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1) bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1) bitmap.font.color.set(255, 255, 255) bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1) end @_damage_sprite = ::Sprite.new(self.viewport) @_damage_sprite.bitmap = bitmap @_damage_sprite.ox = 80 @_damage_sprite.oy = 20 @_damage_sprite.x = self.x @_damage_sprite.y = self.y - self.oy / 2 @_damage_sprite.z = 3000 @_damage_duration = 40 end def pushAnimation(array,anim) for i in 0...array.length if !array[i] || !array[i].active? array[i]=anim return end end array.push(anim) end def animation(animation, hit) anim=SpriteAnimation.new(self) anim.animation(animation,hit) pushAnimation(@animations,anim) end def loop_animation(animation) anim=SpriteAnimation.new(self) anim.loop_animation(animation) pushAnimation(@loopAnimations,anim) end def dispose_damage if @_damage_sprite != nil @_damage_sprite.bitmap.dispose @_damage_sprite.dispose @_damage_sprite = nil @_damage_duration = 0 end end def dispose_animation for a in @animations a.dispose_animation if a end @animations.clear end def dispose_loop_animation for a in @loopAnimations a.dispose_loop_animation if a end @loopAnimations.clear end def blink_on unless @_blink @_blink = true @_blink_count = 0 end end def blink_off if @_blink @_blink = false self.color.set(0, 0, 0, 0) end end def blink? @_blink end def effect? return true if @_whiten_duration > 0 or @_appear_duration > 0 or @_escape_duration > 0 or @_collapse_duration > 0 or @_damage_duration > 0 for a in @animations return true if a.effect? end return false end def update super if @_whiten_duration > 0 @_whiten_duration -= 1 self.color.alpha = 128 - (16 - @_whiten_duration) * 10 end if @_appear_duration > 0 @_appear_duration -= 1 self.opacity = (16 - @_appear_duration) * 16 end if @_escape_duration > 0 @_escape_duration -= 1 self.opacity = 256 - (32 - @_escape_duration) * 10 end if @_collapse_duration > 0 @_collapse_duration -= 1 self.opacity = 256 - (48 - @_collapse_duration) * 6 end if @_damage_duration > 0 @_damage_duration -= 1 case @_damage_duration when 38..39 @_damage_sprite.y -= 4 when 36..37 @_damage_sprite.y -= 2 when 34..35 @_damage_sprite.y += 2 when 28..33 @_damage_sprite.y += 4 end @_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32 if @_damage_duration == 0 dispose_damage end end for a in @animations a.update end for a in @loopAnimations a.update end if @_blink @_blink_count = (@_blink_count + 1) % 32 if @_blink_count < 16 alpha = (16 - @_blink_count) * 6 else alpha = (@_blink_count - 16) * 6 end self.color.set(255, 255, 255, alpha) end SpriteAnimation.clear end def update_animation for a in @animations a.update_animation if a && a.active? end end def update_loop_animation for a in @loopAnimations a.update_loop_animation if a && a.active? end end def x=(x) sx = x - self.x for a in @animations a.x=x if a end for a in @loopAnimations a.x=x if a end super end def y=(y) sy = y - self.y for a in @animations a.x=x if a end for a in @loopAnimations a.x=x if a end super end end end 2)copy the Ani class script and paste below RPG::Sprite ( it can be anywhere below it) CODE class Ani < RPG::Sprite attr_accessor :anim def initialize super(Viewport.new(0, 0, 640, 480)) end
def mio(num,x,y) @num = num self.x = x self.y = y self.z = 8000 @animation_call = $data_animations[@num] @frame_count = @animation_call.frame_max animation(@animation_call, true) end
def animation(animation, hit) @anim=SpriteAnimation.new(self) @anim.animation(animation,hit) pushAnimation(@animations,anim) super_update end def super_update for i in 0 ... @frame_count Graphics.update @anim.update end @anim.update @anim.dispose self.dispose Graphics.update end end I have an example of a title screen undergoing the fire3 animation  (later added) please report any errors, glitches, etc, with this. It is new and I am still debugging it. I will be posting updates and i will modify the existing code, hopefully I will be able to reduce it to one script. For now it works relatively fine on the game map, but it is buggy in handmade scenes. I hope to have that fixed soon. I do thank all those who give this script a try. ~~~~~~~~~~~~~~~~~~~~~~~~~~end of outdated~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This post has been edited by MCgamer: Mar 26 2009, 11:37 AM
__________________________
March 4 2012: After 2 years, It's good to be back.
|
|
|
|
|
|
|
|
|
Jan 3 2009, 08:37 PM
|

Current Mood: eternally happy @_@

Group: +Gold Member
Posts: 1,291
Type: Event Designer
RM Skill: Undisclosed

|
Sorry about the topic kick, but in case you ever return, this is a very useful script, and I haven't (yet) found any errors. Thanks for making this! I plan to make full use of it.
__________________________
GoldenGriffon
Coming out of game-making retirement?
|
|
|
|
|
|
|
|
|
Feb 4 2009, 10:57 PM
|

Level 3

Group: Member
Posts: 41
Type: Scripter
RM Skill: Skilled

|
I have done it!!!!! I have gotten a new Animator class created that is one script instead of two and much shorter. It has new options too and works with hand written scene classes, and no glitches of the flash sticking around. Oh, instead of using Ani.new() you now use $ani.method with the methods being listed below: options: 1) $ani.run(ani_id, x, y) 2) $ani.run(ani_id, x, y, z) 3) $ani.run(ani_id, x, y, hit) 4) $ani.run(ani_id, x, y,z, hit) 5) $ani.timed_ani(ani_id, x, y, z, numberOfTimesToRun, lengthOfTimeOverWhichToRun) 6) $ani.flash(color, duration) 7) $ani.timed_flash(color, numberOfTimesToRun, lengthOfTimeOverWhichToRun) 8) $ani.timed_flash(color, numberOfTimesToRun, lengthOfTimeOverWhichToRun, seAudioNameToPlayEachTime) my personal favorite is #8 as it can be used to do lightning oooh:) lightning ex) CODE $ani.timed_flash( Color.new(100,0,0), 4,20, "Audio/SE/061-Thunderclap01");
Just a note: For sounds, you might need to export them to the Audio/SE folder to play them ~ I'm unsure though as to whether you absolutely need to do that. The timed methods use a thread, so they will run the specified number of times until done, even if you should change what map you're on or even if you change the $scene variable. They are independent of anything going on in the game. Though seeing as they exist within the main thread running the rmxp made game, if that should end, they will too. The variable names are pretty self explanatory please feel free to mention any new methods you want added and if I have time, I'll add them here.(or you might post them in a reply) CODE
#Made by MCgamer @2009 , to use or modify it, just say I made the original and what changes you've made.
#this win32api is from Squall's win32 api screen size changer #it is used primarily for getting screen size #squall@loeher.znn.com class Win32API #-------------------------------------------------------------------------- # â— define constant #-------------------------------------------------------------------------- GAME_INI_FILE = ".\\Game.ini" # define "Game.ini" file HWND_TOPMOST = 0 # window always active HWND_TOP = -1 # window active when used only SWP_NOMOVE = 0 # window pos and sizes can be changed #-------------------------------------------------------------------------- # â— Win32API.GetPrivateProfileString // check your game title in Game.ini #-------------------------------------------------------------------------- def Win32API.GetPrivateProfileString(section, key) val = "\0"*256 gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l') gps.call(section, key, "", val, 256, GAME_INI_FILE) val.delete!("\0") return val end #-------------------------------------------------------------------------- # â— Win32API.FindWindow // find the RGSS window #-------------------------------------------------------------------------- def Win32API.FindWindow(class_name, title) fw = Win32API.new('user32', 'FindWindow', %(p, p), 'i') hWnd = fw.call(class_name, title) return hWnd end #-------------------------------------------------------------------------- # â— Win32API.SetWindowPos // change window positions #-------------------------------------------------------------------------- def Win32API.SetWindowPos(w, h) title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i') win = swp.call(hWnd, HWND_TOP, 150, 50, w+6,h+32, 0)
#the line below makes the window on top of all others #win = swp.call(hWnd, HWND_TOPMOST, 0, 0, w + 6, h + 32, SWP_NOMOVE) return win end #-------------------------------------------------------------------------- # â— Win32API.client_size // check the window width and height #-------------------------------------------------------------------------- def Win32API.client_size title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) rect = [0, 0, 0, 0].pack('l4') Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hWnd, rect) width, height = rect.unpack('l4')[2..3] return width, height end
end
$width , $height = Win32API.client_size();
#===================================================# # # #===================================================#
class Animator
def initialize()
@viewer = Viewport.new(0,0,$width, $height) @viewer.visible = true; @viewer.z = 20000 @anime = RPG::Sprite.new(); end def dispose() @anime.dispose(); end #================================# ################################## def run(*args) if args.size > 5 or args.size < 3 return; elsif args.size == 5 runANI(args[0],args[1],args[2],args[3],args[4]); elsif args.size == 3 runV1(args[0],args[1],args[2]); elsif args.include?(true) or args.include?(false) runV3(args[0],args[1],args[2],args[3]); else runV2(args[0],args[1],args[2],args[3]); end end #each V stands for "version" def runV3(ani_id, x, y, hit) runANI(ani_id, x, y, 2000, hit); end def runV2(ani_id, x, y, z) runANI(ani_id, x, y, z, true); end def runV1(ani_id, x, y) runANI(ani_id, x, y, 2000, true); end #=============================# def runANI(ani_id, x, y, z, hit) #establish location @anime.x = x; @anime.y = y; @anime.z = z; anim = $data_animations[ani_id]; size = anim.frame_max; @anime.animation(anim, hit); #run animation for i in 0...size @anime.update(); Graphics.update(); end @anime.dispose(); @anime = RPG::Sprite.new(); end #================================# ################################## #this will run it the number of times you want #with some spacing in between. def timed_ani(ani_id, x=100, y=100, z=2000, howManyTimes = 1, overWhatPeriodOfTime = 1) interval = overWhatPeriodOfTime / howManyTimes; interval = 5 if interval < 5; #@viewer = Viewport.new(0,0,$width, $height) Thread.new(){ for i in 0...howManyTimes @anime.x = x; @anime.y = y; @anime.z = z; anim = $data_animations[ani_id]; size = anim.frame_max; @anime.animation(anim, true); for i in 0...size @anime.update(); Graphics.update(); end @anime.dispose(); @anime = RPG::Sprite.new(); sleep(interval); end } end #================================# ################################## #good for lightning effects or any periodic flashes for that matter. def timed_flash(color = color.new(0,0,0,0), howManyTimes = 1, overWhatPeriodOfTime = 1,#note this is in seconds seAudioName = nil) interval = overWhatPeriodOfTime / howManyTimes; interval = 5 if interval < 5; #@viewer = Viewport.new(0,0,$width, $height) Thread.new(){ for i in 0...howManyTimes $ani.flash(color, 14); Audio.se_play(seAudioName) if seAudioName != nil; Graphics.update(); sleep(4); Audio.se_stop(); sleep(interval-4); end } end #========================# def flash(newcolor, duration ) #@viewer = Viewport.new(0,0,$width, $height) @viewer.flash(newcolor, duration); for i in 0... duration @viewer.update() Graphics.update() end end
end #end of class
$ani = Animator.new
#========================
This post has been edited by MCgamer: Feb 4 2009, 11:09 PM
__________________________
March 4 2012: After 2 years, It's good to be back.
|
|
|
|
|
|
|
|
|
Mar 26 2009, 11:13 AM
|

Level 3

Group: Member
Posts: 41
Type: Scripter
RM Skill: Skilled

|
Animator 2.6 is up and in need of some help to improve efficiency to a new method added. CODE
#################################### scripter: MCgamer
####################################
#win32api is from Squall's win32 api screen size changer #squall@loeher.znn.com class Win32API #-------------------------------------------------------------------------- # — define constant #-------------------------------------------------------------------------- GAME_INI_FILE = ".\\Game.ini" # define "Game.ini" file HWND_TOPMOST = 0 # window always active HWND_TOP = -1 # window active when used only SWP_NOMOVE = 0 # window pos and sizes can be changed #-------------------------------------------------------------------------- # — Win32API.GetPrivateProfileString // check your game title in Game.ini #-------------------------------------------------------------------------- def Win32API.GetPrivateProfileString(section, key) val = "\0"*256 gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l') gps.call(section, key, "", val, 256, GAME_INI_FILE) val.delete!("\0") return val end #-------------------------------------------------------------------------- # — Win32API.FindWindow // find the RGSS window #-------------------------------------------------------------------------- def Win32API.FindWindow(class_name, title) fw = Win32API.new('user32', 'FindWindow', %(p, p), 'i') hWnd = fw.call(class_name, title) return hWnd end #-------------------------------------------------------------------------- # — Win32API.SetWindowPos // change window positions #-------------------------------------------------------------------------- def Win32API.SetWindowPos(w, h) title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i') win = swp.call(hWnd, HWND_TOP, 150, 50, w+6,h+32, 0)
#the line below makes the window on top of all others #win = swp.call(hWnd, HWND_TOPMOST, 0, 0, w + 6, h + 32, SWP_NOMOVE) return win end #-------------------------------------------------------------------------- # — Win32API.client_size // check the window width and height #-------------------------------------------------------------------------- def Win32API.client_size title = Win32API.GetPrivateProfileString("Game", "Title") hWnd = Win32API.FindWindow("RGSS Player", title) rect = [0, 0, 0, 0].pack('l4') Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hWnd, rect) width, height = rect.unpack('l4')[2..3] return width, height end
end
$width , $height = Win32API.client_size();
#===================================================# #Animator 2.6# #===================================================#
class Animator
def initialize() #========================================================= #change if you want weather to run during non map scenes @run_weather_in_non_map_scenes = false #==============================
@viewer = Viewport.new(0,0,$width, $height) @viewer.visible = true; @viewer.z = 20000 @weather1 = Viewport.new(0,0,$width, $height) @weather1.visible = true; @weather1.z = 20002 @continueWeather = false; @anime = RPG::Sprite.new(); end def dispose() @viewer.dispose(); @weather1.dispose(); @anime.dispose(); end #================================# ################################## def run(*args) if args.size > 5 or args.size < 3 return; elsif args.size == 5 runANI(args[0],args[1],args[2],args[3],args[4]); elsif args.size == 3 runV1(args[0],args[1],args[2]); elsif args.include?(true) or args.include?(false) runV3(args[0],args[1],args[2],args[3]); else runV2(args[0],args[1],args[2],args[3]); end end #each V stands for "version" def runV3(ani_id, x, y, hit) runANI(ani_id, x, y, 2000, hit); end def runV2(ani_id, x, y, z) runANI(ani_id, x, y, z, true); end def runV1(ani_id, x, y) runANI(ani_id, x, y, 2000, true); end #=============================# def runANI(ani_id, x, y, z, hit) #establish location @anime.x = x; @anime.y = y; @anime.z = z; anim = $data_animations[ani_id]; size = anim.frame_max; @anime.animation(anim, hit); #run animation for i in 0...size @anime.update(); #$scene.update() if $scene.respond_to?(:update) Graphics.update(); end @anime.dispose(); @anime = RPG::Sprite.new(); end #================================# ################################## #this will run it the number of times you want #with some spacing in between. def timed_ani(ani_id, x=100, y=100, z=2000, howManyTimes = 1, overWhatPeriodOfTime = 1) interval = overWhatPeriodOfTime / howManyTimes; interval = 5 if interval < 5; Thread.new(){ for i in 0...howManyTimes @anime.x = x; @anime.y = y; @anime.z = z; anim = $data_animations[ani_id]; size = anim.frame_max; @anime.animation(anim, true); for i in 0...size @anime.update(); #$scene.update() if $scene.respond_to?(:update) Graphics.update(); end @anime.dispose(); @anime = RPG::Sprite.new(); sleep(interval); end } end #================================# ################################## #good for lightning effects or any periodic flashes for that matter. def timed_flash(color = color.new(0,0,0,0), howManyTimes = 1, overWhatPeriodOfTime = 1,#note this is in seconds seAudioName = nil) interval = overWhatPeriodOfTime / howManyTimes; interval = 5 if interval < 5; #@viewer = Viewport.new(0,0,$width, $height) Thread.new(){ for i in 0...howManyTimes $ani.flash(color, 14); Audio.se_play(seAudioName) if seAudioName != nil; Graphics.update(); sleep(4); Audio.se_stop(); sleep(interval-4); end } end #========================# def flash(newcolor, duration ) #@viewer = Viewport.new(0,0,$width, $height) @viewer.flash(newcolor, duration); for i in 0... duration @viewer.update() Graphics.update() end end ############################################## #drive weather patterns ############################################## #this will alternate back and forth between #desired weather(s)(it will always show all of them at the same time) #and none, always varying in intensity. #This will drive the weather continuously so you do have to make a #call to $ani.cease_weather() if you want it to stop short of leaving the map. #which if you do leave the map (ie go to Scene_Title) it will stop on its own. #all timing is in terms of seconds #intensity is from 2 to 40 #any intensity greater than 40 will likely be too resource intensive for #your computer to handle, otherwise I would just make a second #call to weather with the second call having maxIntensity lowered by 40 #input:duration wait,max intensity, and any number(s)from the weather list. #For possible weathers, use following list: #1 = rain #2 = storm #3 = snow #ex of three weathers on top of eachother) $ani.weather(4,8, 10, 1,2,3) #duration and wait affect how often the thread calls update #!!!!!!!!!!WARNING!!!!!!!!!!!!!!! #the weather method might not be compatible with the timed_ani() or run() methods #if your computer has limited cpu resources and will make game end if that #be the case that too many threads got called for this game. #Weather is however, compatible with timed_flash #This also looks cools if an event makes a call to the fog settings #and uses clouds ################################################################## def weather(duration,wait,maxIntensity, *weathers) #weather(duration,wait,maxIntensity-40, weathers) if maxIntensity > 40 maxIntensity = 40 if maxIntensity > 40; @continueWeather = true; weather = RPG::Weather.new(@weather1); weather.type = weathers[0] weather.max = maxIntensity; if weathers.size == 2 weather2 = RPG::Weather.new(@weather1); weather2.type = weathers[1] weather2.max = maxIntensity; elsif weathers.size == 3 weather2 = RPG::Weather.new(@weather1); weather2.type = weathers[1] weather2.max = maxIntensity; weather3 = RPG::Weather.new(@weather1); weather3.type = weathers[2] weather3.max = maxIntensity; else weather2 = nil; weather3 = nil; end duration = 10 if duration < 10; wait = 2 if wait < 0; maxIntensity = 2 if maxIntensity < 2; #======# Thread.new(){ while @continueWeather == true if @run_weather_in_non_map_scenes == false and $scene.class != Scene_Map weather.type = 0 weather2.type = 0 if weather2 != nil; weather3.type = 0 if weather3 != nil; @continueWeather = false duration = 0; end weather.max = maxIntensity/3 weather2.max = maxIntensity/3 if weather2 != nil; weather3.max = maxIntensity/3 if weather3 != nil; weather.type = weathers[0]; weather2.type = weathers[1] if weather2 != nil; weather3.type = weathers[2] if weather3 != nil; for i in 0...duration $scene.update() if $scene.class == Scene_Map weather.update(); weather2.update() if weather2 != nil weather3.update() if weather3 != nil Graphics.update(); end weather.max = maxIntensity weather2.max = maxIntensity if weather2 != nil; weather3.max = maxIntensity if weather3 != nil; for i in 0...duration $scene.update() if $scene.class == Scene_Map duration = 0 if @continueWeather == false weather.update(); weather2.update() if weather2 != nil weather3.update() if weather3 != nil Graphics.update(); end if @run_weather_in_non_map_scenes == false and $scene.class != Scene_Map weather.type = 0 weather2.type = 0 if weather2 != nil; weather3.type = 0 if weather3 != nil; @continueWeather = false duration = 0; end #soften effect of cutting out weather weather.max = weather.max/2; weather2.max = weather2.max/2 if weather2 != nil; weather3.max = weather3.max/2 if weather3 != nil; for i in 0...duration duration = 0 if @continueWeather == false $scene.update() if $scene.class == Scene_Map weather.update(); weather2.update() if weather2 != nil weather3.update() if weather3 != nil Graphics.update(); end weather.max = weather.max/2; weather2.max = weather2.max/2 if weather2 != nil; weather3.max = weather3.max/2 if weather3 != nil; for i in 0...duration $scene.update() if $scene.class == Scene_Map duration = 0 if @continueWeather == false weather.update(); weather2.update() if weather2 != nil weather3.update() if weather3 != nil Graphics.update(); end
#clear weather before wait weather.type = 0; weather2.type = 0 if weather2 != nil; weather3.type = 0 if weather3 != nil; weather.update(); weather2.update() if weather2 != nil weather3.update() if weather3 != nil Graphics.update(); sleep(wait); end weather.dispose(); weather2.dispose if weather2 != nil; weather3.dispose if weather3 != nil; sleep(1); } end #========================================== def cease_weather() @continueWeather = false; #having a line after changing continueWeather is crucial to #keep the computer going for some reason. #it freezes up if the line is removed hello = "yes" end
end
$ani = Animator.new
This one has a new major method added called "weather" that can drive continuously up to three weathers (with the option to do so in a non map scene if you change the variable that tells it not to). There is also a small method called "cease_weather" that will tell the thread in $ani to stop driving the weather. The weather method looks like this: 9)$ani.weather(duration,wait,maxIntensity, *weathers) 10)$ani.cease_weather()Instructions are in script, but quick run down is this: duration :number of frames to run at any given intensity wait : seconds between weather disappearing and reappearing maxIntensity : an int between 2 and 40 with 40 being the max (any thing more intense can be done by making additional calls to $ani.weather though this tends to produce more threads then my laptop likes but does work up to a point for me(two to four threads); it might work on higher number of threads easily on other computers like desktops, I haven't tried it on one though)  To think, very heavy blizzards can be done with about 4 threads, though heavy rain requires far fewer and actually looks heavier, but that is just because of how the rain is done by RPG::Weather in the first place. Of course, the more threads you run as part of the main game, the more choppy the movement will be. (i've tried to minimize that by making calls to $scene.update() and graphics.update() and its helped some. If people have or find a better way to make heavy threading not a problem please post here how) "weathers" is a number of ints you supply from the list below(the first three will be used): 1 = rain 2 = storm 3 = snow You can supply multiple of the same number since the order you supply them in simply determines the copy of RPG::Weather (weather1 through weather3) it gets displayed on. This can be adapted to hold more weathers, I think there was a while ago a post with weathers like autumn leaves. This might be made compatible with things like that, but that is for others to try. Here's an example of rain with snow with maxIntensity being 40 but the driver has only just started up the weather. ex) $ani.weather(40,1, 40, 1,3) This works sort of like real weather in that it starts and stops gradually rather than abruptly. Making the inner for loops more like a gradual build up then diminishing afterwards of intensity could probably make this look more realistic. If someone has the time to work on that, I'd love for an update to be posted here. I didn't mark this as animator 3.0 because I don't think this weather driver is as efficient as possible. It is long and has to dictate to the thread a lot of step by step instructions. If you find or know a way to make this more efficient, please post an update here. Did I mention using an event that has a script call to ani and a call to fog settings, setting them to be moving clouds, looks really cool?
This post has been edited by MCgamer: Mar 26 2009, 11:56 AM
__________________________
March 4 2012: After 2 years, It's good to be back.
|
|
|
|
|
|
|
|
  |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
RPG RPG Revolution is an Privacy
Policy and Legal
|
|