XP Wave Effect
#1
XP Wave Effect
por zecomeia

Introduction

Modifications in Sprite class to use the wave effect of RGSS2.

Features

* Muito fiel ao efeito do RMVX


Screen Shot

[Image: xpeaveeffectss.png]

Download

Demo

Instructions

* Paste the script up of main;
* Use how on RGSS2, if don't know, search for RGSS reference manual in help file of RMVX.

Script

Code:
#========================================
# XP Wave Effect
#----------------------------------------
#by:      zecomeia
#date:    01/03/2010
#for:     RGSS
#version: 1.0
#www.colmeia-do-ze.blogspot.com
#----------------------------------------
=begin
Reproduction of the VX's wave effect
(see the help file of the RPGMaker VX
in the RGSS manual reference topic)
=end

#==============#
# Sprite class #
#==============#
class Sprite
  
  include Math
  
  attr_accessor   :wave_amp
  attr_accessor   :wave_length
  attr_accessor   :wave_speed
  attr_accessor   :wave_phase
  attr_accessor   :temp_bitmap
  
  alias initialize default_initialize rescue nil
  alias default_initialize initialize
  def initialize(viewport=nil)
    @wave_amp = 0
    @wave_length = 180
    @wave_speed = 360
    @wave_phase = 0.0
    default_initialize(viewport)
    @temp_bitmap = nil
  end
  
  alias update default_update rescue nil
  alias default_update update  
  def update()
    # the wave effect only works if wave_amp
    # propertie is a number more than zero
    wave_effect if @wave_amp > 0
    default_update()
  end
  
  # Return the width of image, because when use
  # obj.bitmap.width the value will be more than
  # the original value(because effect)
  def width()
    return (self.bitmap.width - @wave_amp * 2)
  end
    
  #---------------
  # Wave Effect
  #---------------
  def wave_effect()
    return if self.bitmap.nil?
    @temp_bitmap = self.bitmap if @temp_bitmap.nil?
    cw = @temp_bitmap.width + (@wave_amp * 2)
    ch = @temp_bitmap.height
    # Follow the VX wave effect, each horizontal line
    # has 8 pixel of height. This device provides less
    # lag in game.
    divisions = @temp_bitmap.height / 8
    divisions += 1 if @temp_bitmap.height % 8 != 0
    self.bitmap = Bitmap.new(cw, ch)
    for i in 0..divisions
      x = @wave_amp * Math.sin(i * 2 * PI / (@wave_length / 8).to_i + Math.deg_to_rad(@wave_phase))
      src_rect = Rect.new(0, i*8, @temp_bitmap.width, 8)
      dest_rect = Rect.new(@wave_amp + x, i * 8, @temp_bitmap.width, 8)
      self.bitmap.stretch_blt(dest_rect, @temp_bitmap, src_rect)
    end
    # frame rate: VX = 60 | XP = 40
    # wave speed compatibility VX to XP: wave_speed * 60/40
    # then: wave_speed * 1.5
    @wave_phase += @wave_speed * 1.5 / @wave_length
    @wave_phase -= 360 if @wave_phase > 360
    @wave_phase += 360 if @wave_phase < 0
  end
  
end

#=============#
# module Math #
#=============#
module Math
  
  #-------------------------------
  # Conversion Degree to Radian
  #-------------------------------
  def Math.deg_to_rad(deg)
    return (deg * PI) / 180.0
  end
  
end

Credits and Thanks
zecomeia

[Image: 88x31.png]

Scripts RGSS, Resources, Tutorials and Translations by zecomeia is licensed under a
Creative Commons Atribuição-Uso Não-Comercial-Compartilhamento pela mesma Licença 2.5 Brasil License.
Permissions beyond the scope of this license may be available at Santuário RPG Maker
Reply }
#2
Moving this to the scripts section.

Edit: Haha, I like it! But I get a bit of lag using it. I was trying it out on the title sprite with wave_amp and wave_length set to 320. :P Still, this is pretty cool. :)
Reply }
#3
Quote:Moving this to the scripts section.
Sorry, I was distracted when I posted the script.

Thanks!
The lag is a really problem, but I don't know how to decrease it and keep the normal operation.
I am free for sugestions ^^

Bye
Reply }
#4
only use radians instead of degrees. If you want the user to be able to use degrees, write a setter and a getter that converts it.

Im not sure how optimized the cos() and sin() functions are in ruby. It might be faster if you calc the values of the cos() and sin() when the game starts, and cache it into a table, so that you don't have to calc it every frame update.
Reply }
#5
Nice! and doesn't lag very much for me, just a little bit.
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Breath Effect LiTTleDRAgo 0 4,329 05-15-2017, 09:05 AM
Last Post: LiTTleDRAgo
   ATOA Status Effect Pops DerVVulfman 6 12,445 01-29-2016, 06:30 AM
Last Post: Lightness
   Modify Battler Collapse Effect PK8 2 11,245 04-03-2012, 03:04 AM
Last Post: PK8



Users browsing this thread: 3 Guest(s)