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.

How to make the script run faster without Lag ?

Hi,

I am into making my first game, and I would like to show life in the form of hearts on the top left corner of the map screen. I just need to show life don;t want SP, exp  etc. So changed some of the the line of a script already posted here. Thanks to him, the script is working and hhearts are showing up. All good till there.

The problem is once the life scipt is called. the game becomes super slow. The character takes years to move from one side to other side :(

I am not sure whether this is because I am calling this script as an event using page 3. option script.
then I gave it as Window_Hud.new. thats all....

Please find below the entire thing I used for this. I don't want to use any other conples scripts or SDK for this ... I just taking my first steps in understanding how it works,


    class Window_Hud < Window_Base
      def initialize
        super(-16, -16, 672, 512)
        self.contents = Bitmap.new(width - 32, height - 32)
        self.contents.font.name = "Georgia"
        self.contents.font.bold = true
        self.contents.font.size = 14
        self.opacity = 0
        self.contents_opacity = $game_player.screen_y < 128 ? 90 : 255
        @hp = 0
        @maxhp = 0
        update
      end
      def refresh
        self.contents.clear
        @hp = $game_party.actors[0].hp
        @maxhp = $game_party.actors[0].maxhp
        @x = 32
      @y = 16
        hearts = @maxhp / 250
        for i in 1..hearts
          x = ((i - 1) % 20) * 16 + @x
          y = ((i - 1) / 20) * 16 + 4
          if @hp >= i * 250
            bitmap = RPG::Cache.icon('HeartF')
          elsif (@hp < i * 250) && (@hp > (i - 1) * 250)
            bitmap = RPG::Cache.icon('HeartH')
          else
            bitmap = RPG::Cache.icon('HeartE')
          end
          self.contents.blt(x, y + 8, bitmap, Rect.new(0, 0, 16, 16))
        end
      end
     
      def update
        refresh unless (@hp == $game_party.actors[0].hp and
                        @maxhp == $game_party.actors[0].maxhp)

      end 









Pease help !
 
replace your entire script with this:
    class Window_Hud < Window_Base
      def initialize
        super(-16, -16, 672, 512)
        self.contents = Bitmap.new(width - 32, height - 32)
        self.contents.font.name = "Georgia"
        self.contents.font.bold = true
        self.contents.font.size = 14
        self.opacity = 0
        self.contents_opacity = $game_player.screen_y < 128 ? 90 : 255
        @hp = 0
        @maxhp = 0
        update
      end
      def refresh
        self.contents.clear
        @hp = $game_party.actors[0].hp
        @maxhp = $game_party.actors[0].maxhp
        @x = 32
       @y = 16
        hearts = @maxhp / 250
        for i in 1..hearts
          x = ((i - 1) % 20) * 16 + @x
          y = ((i - 1) / 20) * 16 + 4
          if @hp >= i * 250
            bitmap = RPG::Cache.icon('Heart')
          elsif (@hp < i * 250) && (@hp > (i - 1) * 250)
            bitmap = RPG::Cache.icon('Heart')
          else
            bitmap = RPG::Cache.icon('Heart')
          end
          self.contents.blt(x, y + 8, bitmap, Rect.new(0, 0, 16, 16))
        end
      end
     
      def update
        refresh unless (@hp == $game_party.actors[0].hp and
                        @maxhp == $game_party.actors[0].maxhp)
      end
       end 
class Scene_Map
alias init_hud initialize
alias hud_update update
def initialize
     init_hud
  @hud = Window_Hud.new
end
def update
   hud_update
  @hud.update
end
end

That create the hud and updates it,
won't lag at all..
mods,
please move this topic to RGSS Support.

Venetia: Next time, utilize the "report" function in the bottom right corner of the post, so it can be dealt with quicker. 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