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

Egg Hatch Animation

FL

Pokémon Island Creator
2,449
Posts
13
Years
    • Seen today
    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

    • hatchsheet.png
      hatchsheet.png
      2 KB · Views: 198
    • egghatchscreen.png
      egghatchscreen.png
      1.6 KB · Views: 168
    63
    Posts
    9
    Years
    • Seen Aug 15, 2017
    I'm looking forward to using this and testing it out =] You are better equipped for this than me =]
     

    FL

    Pokémon Island Creator
    2,449
    Posts
    13
    Years
    • Seen today
    Pokémon Essentials does not include a hatch anim?
    When i test ur code i'll edit my message :P
    Few hours after your post, Essentials v14 came with this script integrated.
     
    18
    Posts
    9
    Years
    • Seen Apr 18, 2015
    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?
     
    18
    Posts
    9
    Years
    • Seen Apr 18, 2015
    Up (I am violating the rules of the forum? If yes, sorry
    3.%20frown.gif
    )
     

    FL

    Pokémon Island Creator
    2,449
    Posts
    13
    Years
    • Seen today
    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).
     

    Enigmatic Emolga

    abandoned account, pls delete if seen
    30
    Posts
    11
    Years
  • 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?
     

    FL

    Pokémon Island Creator
    2,449
    Posts
    13
    Years
    • Seen today
    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?
    After line 'def pbEndScene' add line '$game_map.autoplay'.
     
    Back
    Top