Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

SLiding A Window Without def Update

Firstly, the script in question:

Code:
#==============================================================================
# Window_LevelUpWindow
#------------------------------------------------------------------------------
# Base from fukuyama's
# Compiled by Syvkal
#==============================================================================

class Window_LevelUpWindow < Window_Base

#--------------------------------------------------------------------------
# Window size
#--------------------------------------------------------------------------

def initialize(actor, last_lv, up_hp, up_sp, up_str, up_dex, up_agi, up_int)
 super(0, 0, 640, 340)
 self.contents = Bitmap.new(width - 32, height - 32)
 self.back_opacity = 0
 self.opacity = 0
 self.visible = false
 refresh(actor, last_lv, up_hp, up_sp, up_str, up_dex, up_agi, up_int)
end

#--------------------------------------------------------------------------
# Editable part of contents
#--------------------------------------------------------------------------

def refresh(actor, last_lv, up_hp, up_sp, up_str, up_dex, up_agi, up_int)
 self.contents.clear
 draw_actor_body(actor,320,0,255)
 self.contents.font.size = 36
 self.contents.font.outline = true
 self.contents.font.underline = true
 self.contents.font.color = Color.orange
 self.contents.draw_text( 170, 48, 260, 48, "LEVEL UP:  "+actor.name+" Lv"+actor.level.to_s)
 self.contents.font.underline = false
 self.contents.font.color = system_color
 self.contents.draw_text( 170,  80,  160, 48, $data_system.words.hp)
 self.contents.draw_text( 170,  110, 160, 48, $data_system.words.sp)
 self.contents.draw_text( 170,  140,  80, 48, $data_system.words.str)
 self.contents.draw_text( 170,  170,  80, 48, $data_system.words.dex)
 self.contents.draw_text( 170,  200,  80, 48, $data_system.words.agi)
 self.contents.draw_text( 170,  230,  80, 48, $data_system.words.int)
 self.contents.font.color = normal_color
 #self.contents.draw_text( 0,   0,  88, 24, last_lv.to_s, 2)
 self.contents.draw_text( 170, 80,  260, 48, "+" + up_hp.to_s, 2)
 self.contents.draw_text( 170, 110, 260, 48, "+" + up_sp.to_s, 2)
 self.contents.draw_text( 170, 140, 260, 48, "+" + up_str.to_s, 2)
 self.contents.draw_text( 170, 170, 260, 48, "+" + up_dex.to_s, 2)
 self.contents.draw_text( 170, 200, 260, 48, "+" + up_agi.to_s, 2)
 self.contents.draw_text( 170, 230, 260, 48, "+" + up_int.to_s, 2)
 #self.contents.draw_text( 170,   0, 128, 48, "Lv"+actor.level.to_s, 2)
end
end

#==============================================================================
# Scene_Battle add ons
#------------------------------------------------------------------------------
# Base from fukuyama's
# Compiled by Syvkal
#==============================================================================

#--------------------------------------------------------------------------
# Search for :EDIT:  for parts you can edit.
#--------------------------------------------------------------------------

#==============================================================================
# Window_BattleStatus
#==============================================================================
class Window_BattleStatus < Window_Base
  
#--------------------------------------------------------------------------

 attr_accessor :level_up_flags
end


#==============================================================================
# Game_Battler
#==============================================================================
class Game_Battler
  
#--------------------------------------------------------------------------

attr_accessor :exp_gain_ban

#--------------------------------------------------------------------------

alias xrxs_bp10_initialize initialize
def initialize
 @exp_gain_ban = false
 xrxs_bp10_initialize
end

#--------------------------------------------------------------------------

alias xrxs_bp10_cant_get_exp? cant_get_exp?
def cant_get_exp?
 if @exp_gain_ban == true
   return true
 else
   return xrxs_bp10_cant_get_exp?
 end
end
end


#==============================================================================
# Scene_Battle
#==============================================================================
class Scene_Battle
  
#--------------------------------------------------------------------------

alias xrxs_bp10_start_phase5 start_phase5
def start_phase5
 
 for i in 0...$game_party.actors.size
   $game_party.actors[i].exp_gain_ban = true
 end
 xrxs_bp10_start_phase5
 
 for i in 0...$game_party.actors.size
   $game_party.actors[i].exp_gain_ban = false
 end
 
 @exp_gained = 0
 for enemy in $game_troop.enemies
   
   @exp_gained += enemy.exp if not enemy.hidden
 end
 
 @phase5_step       = 0
 @exp_gain_actor    = -1
 
 @result_window.y -= 0
 @result_window.visible = true
 
 phase5_next_levelup
end

#--------------------------------------------------------------------------

alias xrxs_bp10_update_phase5 update_phase5
def update_phase5
 case @phase5_step
 when 1
   update_phase5_step1
 else
   xrxs_bp10_update_phase5
   
   battle_end(0) if @levelup_window != nil and @phase5_wait_count <= 0
 end
end

#--------------------------------------------------------------------------

def update_phase5_step1
#  Continue trigger, default : Input::C  (Enter)
 if Input.trigger?(Input::C)
   
   @levelup_window.visible = false if @levelup_window != nil
   @status_window.level_up_flags[@exp_gain_actor] = false
   phase5_next_levelup
 end
end

#--------------------------------------------------------------------------

def phase5_next_levelup
 begin
   
   @exp_gain_actor += 1
  
   if @exp_gain_actor >= $game_party.actors.size
     
     @phase5_step = 0
     return
   end
   actor = $game_party.actors[@exp_gain_actor]
   if actor.cant_get_exp? == false
     
     last_level = actor.level
     last_maxhp = actor.maxhp
     last_maxsp = actor.maxsp
     last_str = actor.str
     last_dex = actor.dex
     last_agi = actor.agi
     last_int = actor.int
     
     actor.exp += @exp_gained
     
     if actor.level > last_level
       
       @status_window.level_up(@exp_gain_actor)
       if $data_system_level_up_se != ""
         Audio.se_stop
         #  :EDIT:             Sound effect of level up
         $data_system_level_up_se = "Audio/SE/001-System01"
         #  End :EDIT:
         Audio.se_play($data_system_level_up_se)
       end
       if $data_system_level_up_me != ""
         Audio.me_stop
         #  :EDIT:                Music effect of level up
         $data_system_level_up_me = "Audio/ME/008-Fanfare02"
         Audio.me_play($data_system_level_up_me)
         #  End :EDIT:
       end
       @levelup_window = Window_LevelUpWindow.new(actor, last_level,
         actor.maxhp - last_maxhp, actor.maxsp - last_maxsp, actor.str - last_str,
         actor.dex - last_dex, actor.agi - last_agi, actor.int - last_int)
       #@levelup_window.x = 160 * @exp_gain_actor
       @levelup_window.visible = true
       @phase5_wait_count = 40
       @phase5_step       =  1
       
       @status_window.refresh
       return
     end
   end
 end until false
end
end

Now, normally when I want to make a window slide into position I o something like this:

Code:
def update
   if @the_window.x != 0
      @the_window.x += 4
   end
...
...
...
end

And that works quite perfectly! However, the above script does not have a "def update", and I am not talented enough to figure out where one might go. So, how could I go about making the levelup window slide into place?
 
Very simple.
Code:
class Window_LevelUpWindow
  def update
    super
    self.x += 4 if self.x != 0
  end
end

super is a special method which calls the parent's method of the same name. In this case, Window_LevelUpWindow's parent is Window_Base which does have an update method.

Hope this helps.
 
Wow, got it to work on my first try! So, before this topic gets closed could someone just tell me why I didn't hve to actually call for the update? (i.e. LevelWindow.update). I'm trying to learn. Thanks!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top