• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Staff applications for our PokéCommunity Daily and Social Media team are now open! Interested in joining staff? Then click here for more info!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Essentials Tutorial] [EBS]Cache In-battle animations to fix lag

thepsynergist

Vinemon: Sauce Edition Programmer and Composer
  • 795
    Posts
    15
    Years
    -Made with Pkmn Essentials v17.2 + EBS in mind.

    If you use Pokemon Reborn's Battle Animations files in your game, and you also use the EBS system, you may notice a 1.5 second hang each time the game loads a battle animation. You can remove this lag by caching the animations files. Here's a handy tutorial to help you out!


    -First things first, this will obviously only work if you use Pokemon Reborn's animations. So, download the game and copy over two files from the "Data" folder, and paste them inside the "Data" folder of your project.


    Code:
    PkmnAnimations.rxdata
    Move2anim.dat


    -Then, open your script editor within your project.

    -Go to your EBS Settings (SJPlugins_Settings), and set

    Code:
    CUSTOMANIMATIONS = false REPLACEMISSINGANIM = true

    -Then, make a new script section above "Main", and paste the following code:

    Spoiler:



    -Then, make another new section and paste this:

    Spoiler:



    -Next, go to PField_Metadata, and go to class PokemonTemp, and add the following to the bottom of the class, under forceSingleBattle:

    Code:
      attr_accessor :cachePkmnAnims
      attr_accessor :cachePkmnAnims2


    -After you do that, go to PokeBattle_Scene, in the def pbFindAnimation, where move2anim is referenced and replace the line:

    Code:
    move2anim=load_data("Data/move2anim.dat")
    with
    Code:
    move2anim=pbLoadCachedAnimations2


    -Next, go to the def pbCommonAnimation, and replace the line:

    Code:
    animations=load_data("Data/PkmnAnimations.rxdata")
    with
    Code:
    animations=pbLoadCachedAnimations


    -Right below in pbAnimation, replace the line:

    Code:
    animations=load_data("Data/PkmnAnimations.rxdata")
    with
    Code:
    animations=pbLoadCachedAnimations


    Now, in the script section EliteBattle_2 (or Animations Script if it's renamed) under def PbAnimation, below "anim=animid[0]" replace:

    Code:
    animations=load_data("Data/PkmnAnimations.rxdata")
    with
    Code:
    animations=pbLoadCachedAnimations


    In the script section EliteBattle_7 (), under "if REPLACEMISSINGANIM" right under "anim=animid[0], replace

    Code:
    animations=load_data("Data/PkmnAnimations.rxdata")
    with
    Code:
    animations=pbLoadCachedAnimations


    Lastly, if you happen to use KleinStudio's Transform Mosaic script, go to the class PokeBattle_Scene's def pbAnimation, under anim=animid[0], replace:

    Code:
    animations=load_data("Data/PkmnAnimations.rxdata")
    with
    Code:
    animations=pbLoadCachedAnimations


    Once you do all that, you should have lagless battle animations! Let me know if you have any questions!
     
    Last edited:
    Calling the battleback as this:

    `@scene.sprites["battlebg"].setBitmap("XXX",@scene)` where XXX is the name of the battleback.

    might prevent lag from being formed. I don't have an issue with battleback changing lag, but it might have had to do with how you were calling it.
     
    Last edited:
    You can use
    Spoiler:


    Just to be more organized about the codes, you know? :)

    Nice tutorial, BTW.
     
    I forgot one thing (thanks Vendily). The game won't cache the animations on a new game unless you add this:

    -Next, go to PScreen_Load, and go to the elsif statement mentioning cmdNewGame (should be around line 403), and paste the following directly after the line, "$game_map.autoplay":
    Code:
            pbLoadCachedAnimations
            pbLoadCachedAnimations2
     
    It works perfectly, the problem is that after passing a combat the fps drops (and the character walks with frame stops) and sometimes it can even crash. Why does this happen? I've seen it happen to quite a few people.
     
    Last edited:
    It works perfectly, the problem is that after passing a combat the fps drops (and the character walks with frame stops) and sometimes it can even crash. Why does this happen? I've seen it happen to quite a few people.

    Not sure about the fps drops, but I have seen it crash sometimes in my game when a battle starts, randomly, but I have no idea what is actually causing it. If anyone figures that out, please let me know, and i'll update the thread.
     
    Not sure about the fps drops, but I have seen it crash sometimes in my game when a battle starts, randomly, but I have no idea what is actually causing it. If anyone figures that out, please let me know, and i'll update the thread.

    hi so i hella did not know this was a thing and ended up making my own. it just throws the entire animation file into a global variable at load time, and it calls that variable when checking for animations.
    this was how i did it: fuck forget it i can't post links. it's on one of my devblog posts.
    i dunno if this helps with yours at all, but maybe it does?


    edit:
    psyduck forget it i can't post links.

    i hate this website.
     
    hi so i hella did not know this was a thing and ended up making my own. it just throws the entire animation file into a global variable at load time, and it calls that variable when checking for animations.
    this was how i did it: fuck forget it i can't post links. it's on one of my devblog posts.
    i dunno if this helps with yours at all, but maybe it does?


    edit:


    i hate this website.

    Hi, sorry for my ignorance, but how could I do this with the moves?
     
    Marin helped me out with this one.

    Code:
    alias old_load_data load_data if !defined?(old_load_data)
    alias old_save_data save_data if !defined?(old_save_data)
    
    LOAD_DATA_CACHE = {}
    
    def load_data(filename, cache=false)
      LOAD_DATA_CACHE.fetch(filename) do
        data = old_load_data(filename)
        LOAD_DATA_CACHE[filename] = data if cache
        next data
      end
    end
    
    def save_data(data, filename)
      LOAD_DATA_CACHE[filename] = data
      return old_save_data(data, filename)
    end
    
    def preload_data(filename)
      load_data(filename, true)
      return nil
    end

    You'd call the animation calls in script with:
    animations=load_data("Data/PkmnAnimations.rxdata", true)

    instead of:
    animations=load_data("Data/PkmnAnimations.rxdata")

    I'll have to remake my tutorial sometime, but this prevents the crashing, that I've noticed. You can also use this to cache other stuff, like tilesets, if your tilesets are too large.
     
    Marin helped me out with this one.

    Code:
    alias old_load_data load_data if !defined?(old_load_data)
    alias old_save_data save_data if !defined?(old_save_data)
    
    LOAD_DATA_CACHE = {}
    
    def load_data(filename, cache=false)
      LOAD_DATA_CACHE.fetch(filename) do
        data = old_load_data(filename)
        LOAD_DATA_CACHE[filename] = data if cache
        next data
      end
    end
    
    def save_data(data, filename)
      LOAD_DATA_CACHE[filename] = data
      return old_save_data(data, filename)
    end
    
    def preload_data(filename)
      load_data(filename, true)
      return nil
    end

    You'd call the animation calls in script with:
    animations=load_data("Data/PkmnAnimations.rxdata", true)

    instead of:
    animations=load_data("Data/PkmnAnimations.rxdata")

    I'll have to remake my tutorial sometime, but this prevents the crashing, that I've noticed. You can also use this to cache other stuff, like tilesets, if your tilesets are too large.

    But then would this script be added after "Moves2Anim Cache" and replace "animations = pbLoadCachedAnimations" with "animations = load_data (" Data / PkmnAnimations.rxdata ", true)"?
     
    It would replace it entirely, which is why I have to rewrite the tutorial. This is caching them outside the $Pokemon.Temp, which was causing the crashes, iirc, as that gets flushed occasionally, so the animations that were cached were nil'd when called. That's my theory as to why it was crashing, anyway.
     
    Are you the same andracass from Pokemon Reborn?

    No worries, I got you:

    yup, that's me.
    hopefully if you add this to the end of that link, it'll actually take you to the comment where i go over this.
    /records/183-beta-r53/?do=findComment&comment=1409

    wow i also can't quote urls. what an experience.
     
    you know what, here: i just screencapped the whole post.
    [the picture was going to go here but it isn't here because it doesn't work because nothing works and i'd like to scream now]
    ...this will work, right?
    just kidding. images embed as links and i can't post links.
     
    yup, that's me.
    hopefully if you add this to the end of that link, it'll actually take you to the comment where i go over this.
    /records/183-beta-r53/?do=findComment&comment=1409

    wow i also can't quote urls. what an experience.


    I have followed all the steps but I receive this error when using or receiving any move.

    Spoiler:
     
    Back
    Top