• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • It's time to vote for your favorite Pokémon Battle Revolution protagonist in our new weekly protagonist poll! Click here to cast your vote and let us know which PBR protagonist you like most.
  • 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.

Egg Hatch Animation

FL

Pokémon Island Creator
  • 2,549
    Posts
    14
    Years
    • Seen yesterday
    Code:
    #===============================================================================
    # * Egg Hatch Animation - by FL (Credits will be apreciated)
    #===============================================================================
    #
    # This script is for Pokémon Essentials. It's a egg hatch animation that
    # works even with special eggs like Manaphy egg.
    #
    #===============================================================================
    #
    # To this script works, put it above main and put a picture (a 5 frames
    # sprite sheet) with egg sprite height and 5 times the egg sprite width at
    # Graphics/Pictures/hatchsheet.
    #
    #===============================================================================
    
    class PokemonEggHatchScene
      def pbStartScene(pokemon)
        @sprites={} 
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @pokemon=pokemon
        @pokemon.eggsteps=1 # Just for drawing the egg
        addBackgroundOrColoredPlane(@sprites,"background","evolutionbg",
           Color.new(248,248,248),@viewport)
        @sprites["pokemon"]=PokemonSprite.new(@viewport)
        @sprites["pokemon"].setPokemonBitmap(@pokemon)
        @sprites["pokemon"].x=Graphics.width/2-@sprites["pokemon"].bitmap.width/2
        @sprites["pokemon"].y=Graphics.height/2-@sprites["pokemon"].bitmap.height/2
        @sprites["hatch"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
        @sprites["msgwindow"]=Kernel.pbCreateMessageWindow(@viewport)
        @sprites["overlay"]=BitmapSprite.new(
            Graphics.width,Graphics.height,@viewport)
        @sprites["overlay"].z=200
        @sprites["overlay"].bitmap = Bitmap.new(Graphics.width,Graphics.height)
        @sprites["overlay"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,
            Color.new(255,255,255))
        @sprites["overlay"].opacity = 0
        # Initialize the pokémon
        @pokemon.eggsteps=0
        @pokemon.name=PBSpecies.getName(@pokemon.species)
        @pokemon.trainerID=$Trainer.id
        @pokemon.ot=$Trainer.name
        @pokemon.happiness=120
        @pokemon.timeEggHatched=pbGetTimeNow
        @pokemon.obtainMode=1 # hatched from egg
        @pokemon.hatchedMap=$game_map.map_id
        pbFadeInAndShow(@sprites)
      end
    
      def pbMain
        hatchSheet=AnimatedBitmap.new(_INTL("Graphics/Pictures/hatchsheet"))
        pbBGMPlay("evolv")
        # Egg animation
        updateScene(60)
        pbPositionHatchMask(hatchSheet,0)
        pbSEPlay("ballshake")
        swingEgg(2)
        updateScene(12)
        pbPositionHatchMask(hatchSheet,1)
        pbSEPlay("ballshake")
        swingEgg(2)
        updateScene(24)
        pbPositionHatchMask(hatchSheet,2)
        pbSEPlay("ballshake")
        swingEgg(4,2)
        updateScene(6)
        pbPositionHatchMask(hatchSheet,3)
        pbSEPlay("ballshake")
        swingEgg(8,4)
        updateScene(6)
        pbPositionHatchMask(hatchSheet,4)
        pbSEPlay("recall")
        # Fade and change the sprite
        fadeSpeed=15
        for i in 1..(255/fadeSpeed)
          @sprites["overlay"].opacity=i*fadeSpeed
          updateScene
        end  
        updateScene(40)
        @sprites["pokemon"].setPokemonBitmap(@pokemon)
        @sprites["hatch"].visible=false
        for i in 1..(255/fadeSpeed)
          @sprites["overlay"].opacity=255-i*fadeSpeed
          updateScene
        end
        # Finish scene
        frames=pbCryFrameLength(@newspecies)
        pbBGMStop()
        pbPlayCry(@pokemon)
        frames.times do
          Graphics.update
        end
        pbMEPlay("004-Victory04")
        speciesname = @pokemon.name
        Kernel.pbMessageDisplay(@sprites["msgwindow"],
           _INTL("\\se[]{1} hatched from the Egg!\\wt[80]",speciesname))
        $Trainer.seen[@pokemon.species]=true
        $Trainer.owned[@pokemon.species]=true
        pbSeenForm(@pokemon)
        if Kernel.pbConfirmMessage(
            _INTL("Would you like to nickname the newly hatched {1}?",speciesname))
          nickname=pbEnterText(_INTL("{1}'s nickname?",speciesname),0,10)
          pokemon.name=nickname if nickname!=""
        end
        @sprites["msgwindow"].text=""
      end
      
      def pbPositionHatchMask(hatchSheet,index)
        frames = 5
        frameWidth = hatchSheet.width/frames
        rect = Rect.new(frameWidth*index,0,frameWidth,hatchSheet.height)
        @sprites["hatch"].bitmap.blt(@sprites["pokemon"].x,@sprites["pokemon"].y,
            hatchSheet.bitmap,rect)
      end  
          
      def swingEgg(speed,swingTimes=1) # Only accepts 2, 4 or 8 for speed.
        limit = 8
        targets = [@sprites["pokemon"].x-limit,@sprites["pokemon"].x+limit,
            @sprites["pokemon"].x]
        swingTimes.times do   
          usedSpeed=speed
          for target in targets
            usedSpeed*=-1    
            while(target != @sprites["pokemon"].x)
              @sprites["pokemon"].x+=usedSpeed
              @sprites["hatch"].x+=usedSpeed
              updateScene
            end  
          end
        end
      end  
    
      def updateScene(frames=1) # Can be used for "wait" effect
        frames.times do
          Graphics.update
          Input.update
          self.update
        end
      end  
      
      def update
        pbUpdateSpriteHash(@sprites)
      end
      
      def pbEndScene
        Kernel.pbDisposeMessageWindow(@sprites["msgwindow"])
        pbFadeOutAndHide(@sprites) { update }
        pbDisposeSpriteHash(@sprites)
        @viewport.dispose
      end
    end
    
    class PokemonEggHatchScreen
      def initialize(scene)
        @scene=scene
      end
    
      def pbStartScreen(pokemon)
        @scene.pbStartScene(pokemon)
        @scene.pbMain
        @scene.pbEndScene
      end
    end
    
    def pbHatch(pokemon)
      Kernel.pbMessage(_INTL("Huh?\1"))
      pbFadeOutIn(99999) {
        scene=PokemonEggHatchScene.new
        screen=PokemonEggHatchScreen.new(scene)
        screen.pbStartScreen(pokemon)
      }
    end
     

    Attachments

    • [PokeCommunity.com] Egg Hatch Animation
      hatchsheet.png
      2 KB · Views: 199
    • [PokeCommunity.com] Egg Hatch Animation
      egghatchscreen.png
      1.6 KB · Views: 169
    I'm looking forward to using this and testing it out =] You are better equipped for this than me =]
     
    Pokémon Essentials does not include a hatch anim?
    When i test ur code i'll edit my message :P
     
    If you're using essentials v14, the egg sprite can be found in Battlers\egg.png.
     
    Yes, I already know this
    But I would like to use a different egg image only for this script, because my egg sprite is an animated gif and it is bad for this animation...
    How can I do?
     
    Yes, I already know this
    But I would like to use a different egg image only for this script, because my egg sprite is an animated gif and it is bad for this animation...
    How can I do?
    Change first line '@sprites["pokemon"].setPokemonBitmap(@pokemon)' into '@sprites["pokemon"].bitmap=BitmapCache.load_bitmap("Graphics/Battlers/490egg")' (change for your egg path). You can change the image loaded checking @pokemon variable attributes (like @pokemon.species).
     
    After an egg hatches, the BGM of the map the player is in doesn't start playing again unless the player leaves and re-enters the map. Any way to fix this?
     
    Back
    Top