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.

[Resolved] Help with my hub

Status
Not open for further replies.
Ok I followed a tutorial on this site, and was able to make a nice hub for my game. After I added it to my game my game began to lag. Can some one help me fix this lag problem.

Code:
class Window_Cat < Window_Base
  def initialize
    super(410, 0, 227, 132)
    self.opacity = 127
    self.contents = Bitmap.new(640 - 32, 64 - 32)
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(@actor, 0, -7)
    draw_actor_sp(@actor, 0, 11)
    self.contents.draw_text(0, 30, 200, 32, "Exp to next: " + $game_party.actors[0].next_rest_exp_s)
    self.contents.draw_text(0, 53, 200, 32, "Level " + $game_party.actors[0].level.to_s)
    self.contents.draw_text(0, 70, 640, 32, "Hero: " + @actor.name.to_s)
    self.contents.draw_text(100, 70, 640, 32, "Gold: " + $game_party.gold.to_s)
  end
  def reset_variables
   @actor = $game_party.actors[0]
   @old_hp = @actor ? @actor.hp : 0
   @old_maxhp = @actor ? @actor.maxhp : 0
   @old_sp = @actor ? @actor.sp : 0
   @old_maxsp = @actor ? @actor.maxsp : 0
  end
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)              
  end
end
class Scene_Map
  alias cat_main main
  alias cat_update update
  def main
    @cat = Window_Cat.new
    cat_main
    @cat.dispose
  end
  def update
    @cat.update
    @cat.visible = $game_switches[8]
    cat_update
  end
end
 

Mac

Member

You can't really just change the script to remove lag, go onto the Submitted Scripts section and search for Anti-Lag by Near Fantastica or f0tz!baerchen's lag script, this should help out alot.
 
I have an anti lag script it still causes lag.

-figured it out these lines were causing the lag:
Code:
    self.contents.draw_text(0, 30, 200, 32, "Exp to next: " + $game_party.actors[0].next_rest_exp_s)
    self.contents.draw_text(0, 53, 200, 32, "Level " + $game_party.actors[0].level.to_s)
    self.contents.draw_text(0, 70, 640, 32, "Hero: " + @actor.name.to_s)
    self.contents.draw_text(100, 70, 640, 32, "Gold: " + $game_party.gold.to_s)
 
Mac - you were way off this time, don't worry me and Seph will turn you into a great scripter :D

Remember the causes of lag by scripts
- The Refresh method being called each frame (which usually calls draw_text if its a window)
- The following methods should not be called every frame Bitmap#draw_text, Bitmap#hue_change, and Sprite#angle= as they are time_comsuming methods
- Very Big Loops (loops within loops)
- Creating a large number of objects (Sometimes, I don't know too much technical info about this)

And the cause of your lag is the first thing I stated, the refresh method is being called every frame, thiis was an error in Yeyinde's tutorial and he corrected it but it was probably lost in the hack

but the update method of your HUD should look like this
Code:
  def update
    super
    refresh if (@actor != $game_party.actors[0] or
                @old_hp != @actor ? @actor.hp : 0 or
                @old_maxhp != @actor ? @actor.maxhp : 0 or
                @old_sp != @actor ? @actor.sp : 0 or
                @old_maxsp != @actor ? @actor.maxsp : 0)              
  end

You want the HUD to refresh only if changes were made to the actor, actor's p or maxhp, or actor's sp and maxsp. The old code was actually setting the old stuff to the new stuff and not checking anything so it was always executing the refresh method which in turn calls draw_text which generated the lag

And Also wrong forum, I have moved this to the correct forum
 
Status
Not open for further replies.

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