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] Preload PNG series in cache

Okay, this is my first time asking for this kind of support, and it's to figure HOW to do something in scripting. I've been noodling with scripting for a while, mostly through Atoa's ABS, so I'm not a complete newbie here. I'm still no grand poo-bah of coding, though...

My situation is that the battle transition I want to use for my game is a series of 114 PNGs, rapidly displaying one after another, with a mere one frame wait in between. 90 of those PNGs show before switching to the @next_scene, with the other 24 showing afterwards. The problem that I am running into is that the first time I do this, the battle transition is VERY slow. Afterwards, once things are (I assume) in cache, the transition is very fast.

What I'd like to know is a way to preload everything in cache, even if it's once right before a battle, and then released right after the battle starts. Even if this causes a brief delay before the battle starts, it's better than the choppiness I have seen so far. My code is ugly, but I will post it anyway.

Code:
  def kingdomheartstrans(frames=114)

    Audio.se_play("Audio/SE/KingdomHeartsBattleStart",100)

    @khbattlestart = Sprite.new

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00000")

    @khbattlestart.x = 0

    @khbattlestart.y = 0

    @khbattlestart.z = 9999

    @khbattlestart.opacity = 255

    wait(1)

    Graphics.update    

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00001")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00002")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00003")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00004")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00005")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00006")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00007")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00008")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00009")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00010")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00011")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00012")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00013")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00014")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00015")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00016")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00017")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00018")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00019")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00020")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00021")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00022")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00023")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00024")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00025")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00026")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00027")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00028")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00029")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00030")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00031")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00032")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00033")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00034")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00035")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00036")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00037")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00038")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00039")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00040")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00041")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00042")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00043")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00044")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00045")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00046")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00047")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00048")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00049")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00050")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00051")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00052")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00053")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00054")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00055")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00056")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00057")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00058")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00059")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00060")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00061")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00062")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00063")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00064")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00065")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00066")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00067")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00068")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00069")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00070")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00071")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00072")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00073")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00074")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00075")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00076")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00077")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00078")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00079")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00080")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00081")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00082")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00083")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00084")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00085")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00086")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00087")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00088")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00089")

    wait(1)

    @khbattlestart.bitmap = RPG::Cache.battlestart("BattleStartTrans_00090")

      Graphics.freeze

      File.delete('Data/scrn_tmp')

      $scene = @next_scene

      Graphics.transition(20)

    wait(1)

    @khbattlestart.dispose

  end

And for a reference, here is the video of the transition AFTER doing it once (I stage the transition for the purposes of this video to make it look smooth). The transition occurs at approximately the 41 second mark.

http://www.youtube.com/watch?v=K1dPBq0piLg

I have looked in this and other forums, but I don't know WHAT to look for topic-wise. If this has already been addressed and dealt with, I apologize. Just point me in the correct direction, and I will mosey on that way.

Thank you in advance. If any more information is required, I will do my best to be prompt and courteous.

EDIT: I don't know if the poster marks a post as resolved or a moderator. Apologies if I am stepping on anyone's toes here.
 
Hmm.. I think I know what you are asking. Try adding this in Main below begin
Code:
 

for i in 0..90

  RPG::Cache.battlestart(sprintf("BattleStartTrans_000%0d", i))

end

That should actually load all your images when the game is loaded, so loading game is longer, but all images are cache.

Similarly, you can cut your code down with a for loop as well.

Code:
Audio.se_play("Audio/SE/KingdomHeartsBattleStart",100)

@khbattlestart = Sprite.new

@khbattlestart.z = 9999

for i in 0..90

  @khbattlestart.bitmap = RPG::Cache.battlestart(sprintf("BattleStartTrans_000%0d", i))

  wait(1)

end

Graphics.freeze

 
 
Alright!

I tried it out, had to modify a few things (mostly how I named the PNGs in the directory), and it works. This is what I ended up doing. For Main, I did this:

Code:
  for i in 0..114

    RPG::Cache.battlestart(sprintf("BattleStart (%0d)", i))

  end

Then for the start of the battle transition, I did this:

Code:
      Audio.se_play("Audio/SE/KingdomHeartsBattleStart",100)

      @khbattlestart = Sprite.new

      @khbattlestart.z = 9999

      for i in 0..90

        @khbattlestart.bitmap = RPG::Cache.battlestart(sprintf("BattleStart (%0d)", i))

        wait(1)

      end

      Graphics.freeze

And in the Battle Scene (for Atoa's Engine), I just added this:

Code:
      Audio.se_play("Audio/SE/KingdomHeartsBattleStart",100)

      @khbattlestart = Sprite.new

      @khbattlestart.z = 9999

      for i in 91..114

        @khbattlestart.bitmap = RPG::Cache.battlestart(sprintf("BattleStart (%0d)", i))

        wait(1)

      end

      Graphics.freeze

The result is seemless, flawless, and (best of all) smooth and quick!

Thank you very much, SephirothSpawn, for your prompt assistance. The load time on the game is minimal, and the size of the game in memory isn't that much larger. In short, this is a win-win situation. Thank you again!
 
Well, you could also make a module method (and paste it above main) and call it by passing a single argument to the method just like this...

[rgss]module KHBattleStart
  def self.bitmaps(range)
    for i in range
      @khbattlestart.bitmap = RPG::Cache.battlestart(sprintf("BattleStart (%0d)", i))
      wait(1)
    end
  end
end
[/rgss]

Then you'd call it like this from any scene...

KHBattleStart.bitmaps(0..90)
 

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