• 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?".
  • 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.

Changing a Pokémon's Sprite during a move animation

26
Posts
10
Years
    • Seen Jan 30, 2016
    How would I go about changing the Pokémon's sprite while it is using a move, and then changing it back after the move is finished?
    I basically want to accomplish the following:
    Ampharos' basic front sprite is 181.png. If my Ampharos uses a move, my Ampharos' sprite changes to display, say, 181a.png instead of 181.png. When the move's animation ends, Ampharos' sprite changes back to 181.png.
    How would I go about coding this? Would it even be possible without rewriting a HUGE portion of Essentials?
    Thank you in advance! ^^
     
    95
    Posts
    9
    Years
    • Seen Jun 18, 2016
    It should be easy adding a new form to Ampharos. Name the sprite 181_1 if you don't have Mega-Ampharos introduced in your game, name it 181_2 if you have Mega-Ampharos.

    Then, add a new Pokémon form in PokemonMultipleForms for Ampharos (you don't need to give him new stats or anything, just a blank new form)

    Then go to PokeBattle_Battler, inside the def pbTryUseMove, paste something like this:

    Code:
    if isConst?(self.species,PBSpecies,:AMPHAROS) && hp>0
           @pokemon.form=1 #Or 2 if you have Mega-Ampharos
           pbCheckForm
          end

    That should make Ampharos change form when using any move, now we need to make it so it changes back to form 0 when ending the turn.

    In PokeBattle_Battler, inside the def pbEndTurn put this:

    Code:
    if isConst?(self.species,PBSpecies,:AMPHAROS) && hp>0
           @pokemon.form=0
           pbCheckForm
          end

    I don't know if this will work, but it's a base.
     
    26
    Posts
    10
    Years
    • Seen Jan 30, 2016
    I did consider using alternate forms, but I don't think that would work. I'm trying to make this happen for all Pokémon, not just Ampharos; that was just an example. Also, if possible, I would like it to change back as soon as the move is finished, rather than waiting until the whole turn ends and up to three other Pokémon also go. ^^"
    Thank you for your help, though!
     
    Last edited:

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • The first place to start is in PokeBattle_ActualScene in def pbAnimationCore. This is where the attack animations get partially handled, but that's the part you need. The nice thing about this part is, that you actually have all you need. The variable user, contains the species information and the index number of the pokemon that is launching the attack. So this part is actually quite easy.

    The more annoying part would be re-writing the pbLoadPokemonBitmapSpecies to include more dynamic variables that would manipulate the sprite bitmap name. I actually think this is pointless, and less neat as it would be just creating a new folder, and dumping sprites with the same name but that are different frame in that folder. For example. I'd copy the entire part that I need, just change its name and the destination folder like so
    Code:
    def pbLoadPokemonBitmapATK(pokemon, back=false)
      return pbLoadPokemonBitmapSpeciesATK(pokemon,pokemon.species,back)
    end
    
    # Note: Returns an AnimatedBitmap, not a Bitmap
    def pbLoadPokemonBitmapSpeciesATK(pokemon, species, back=false)
      ret=nil
      bitmapFileName=pbCheckPokemonBitmapFilesATK([species,back,
                                                  (pokemon.gender==1),
                                                  pokemon.isShiny?,
                                                  (pokemon.form rescue 0),
                                                  (pokemon.isShadow? rescue false)])
      # Alter bitmap if supported
      alterBitmap=(MultipleForms.getFunction(species,"alterBitmap") rescue nil)
      if bitmapFileName && alterBitmap
        animatedBitmap=AnimatedBitmap.new(bitmapFileName)
        copiedBitmap=animatedBitmap.copy
        animatedBitmap.dispose
        copiedBitmap.each {|bitmap|
           alterBitmap.call(pokemon,bitmap)
        }
        ret=copiedBitmap
      elsif bitmapFileName
        ret=AnimatedBitmap.new(bitmapFileName)
      end
      return ret
    end
    
    def pbCheckPokemonBitmapFilesATK(params)
      species=params[0]
      back=params[1]
      for i in 0...2**(params.length-2)
        tgender=(i%2==0) ? params[2] : false
        tshiny=((i/2)%2==0) ? params[3] : false
        tform=((i/4)%2==0) ? params[4].to_s : ""
        tshadow=((i/8)%2==0) ? params[5] : false
        bitmapFileName=sprintf("Graphics/Battlers/ATK/%s%s%s%s%s%s",
           getConstantName(PBSpecies,species),
           tgender ? "f" : "",
           tshiny ? "s" : "",
           back ? "b" : "",
           (tform!="" ? "_"+tform : ""),
           tshadow ? "_shadow" : "") rescue nil
        bitmapFileName=sprintf("Graphics/Battlers/ATK/%03d%s%s%s%s%s",
           species,
           tgender ? "f" : "",
           tshiny ? "s" : "",
           back ? "b" : "",
           (tform!="" ? "_"+tform : ""),
           tshadow ? "_shadow" : "") if !pbResolveBitmap(bitmapFileName)
        return pbResolveBitmap(bitmapFileName) if pbResolveBitmap(bitmapFileName)
      end
      return nil
    end
    This part is in PokemonUtilities, btw. I actually forgot one more thing, back in the PokeBattle_ActualScene script, you need to copy this def into the class PokemonBattlerSprite
    Code:
    def setPokemonBitmapATK(pokemon,back=false)
        @_iconbitmap.dispose if @_iconbitmap
        @_iconbitmap=pbLoadPokemonBitmapATK(pokemon,back)
        self.bitmap=@_iconbitmap ? @_iconbitmap.bitmap : nil
      end

    Now when you have something like that, you can just pop back into your def pbAnimationCore, and near the beginning (under @briefmessage=false), change this part
    Code:
    usersprite=(user) ? @sprites["pokemon#{user.index}"] : nil
    targetsprite=(target) ? @sprites["pokemon#{target.index}"] : nil
    to
    Code:
    backsprite=false
    backsprite=true if user.index%2==0
    [email protected][user.index].pokemon
    targetsprite=(target) ? @sprites["pokemon#{target.index}"] : nil
    @sprites["pokemon#{user.index}"].setPokemonBitmapATK(pokemon,backsprite) if targetsprite && !animation.name.include?("Common:") 
    usersprite=(user) ? @sprites["pokemon#{user.index}"] : nil
    The only thing left to do is adding
    Code:
    @sprites["pokemon#{user.index}"].setPokemonBitmap(pokemon,backsprite) if targetsprite && !animation.name.include?("Common:")
    To the very end of the def. This will actually work for both the player, and enemy sprites. And the only preparation you need, would be to dump your sprites in the Graphics/Battlers/ATK/ folder. I'm assuming you wanted to do something like in X/Y where the Pokemon changes the sprite while attacking.
     
    Last edited:
    26
    Posts
    10
    Years
    • Seen Jan 30, 2016
    Yes, that's exactly what I was trying to do!
    Thank you so much!!
    I'll make sure to give credit! ^^ THANK YOU!!!!!!!!
     
    247
    Posts
    10
    Years
  • It works fine but..It doesn't work when there is the opponent move,why? This happen only to me?
     
    Last edited:
    Back
    Top