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

Two questions on pokemon icons

772
Posts
13
Years
    • UK
    • Seen Apr 19, 2024
    First Question
    I have a list of pokemon dex numbers, and for each number i want to display the icon sprite for (the one in graphics/icons)
    The problem i'm having is in displaying a dynamic amount of sprites (since the amount can vary)
    How would i go about this


    The second question
    For the icon sprites in question one, is it possible to darken, or lighten them (based on a condition) like in the image attached? I know i can do it as separate image files, but I'd rather just lighten/darking the existing file since in the long run its less work. If so, how would this be done?


    Thanks for the help
     

    Rayd12smitty

    Shadow Maker
    645
    Posts
    12
    Years
    • Seen Feb 21, 2016
    For the first question do you know the following code at all?
    Code:
    for i in XXX

    This basically does what you described. It does whatever you want for each occurrence in a variable, array, etc. For example,
    Code:
    for i in 0...$Trainer.party.length
    does the following script each time for however many Pokemon are in the party.
     
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    i've got that bit, the problem I've ran into is displaying the sprites themselves.
    Normally to show a sprite i'd use a variation of
    Code:
    @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
    pkmnbitmap=AnimatedBitmap.new(pbPokemonBitmapFile(data[1+t],shi))
    @sprites["overlay"].bitmap.blt(0,0,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
    (though i need to find the one that shows the animated icons like in the party) but am unsure how to do this when i don't know the amount in advance
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • For the First question
    Could you clarify what exactly you want to do a little more? Also what does the data[1+t] store?

    For the Second question
    Sprite.tone does the trick (where tone=Tone.new(r,g,b) ). It can go in the negative value as well as the positive, so you can get the range you want.
     
    10
    Posts
    10
    Years
    • Seen Sep 7, 2018
    For the First question
    Could you clarify what exactly you want to do a little more? Also what does the data[1+t] store?

    For the Second question
    Sprite.tone does the trick (where tone=Tone.new(r,g,b) ). It can go in the negative value as well as the positive, so you can get the range you want.

    I love you, worked like a charm (I'm not the owner of this thread, but I felt like adding it)
     
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    Thanks for the tone info


    I'm basically trying to do similar to what the pokedex does

    i've got it working a long winded way, but i want to make it easier to manage and not have to define each sprite. i know the following displays their sprites, need to find the bit that displays icons instead. i can find the bit that displays if you have a pokemon but not if you just have an dex id

    Code:
    pkmnbitmap=AnimatedBitmap.new(pbPokemonBitmapFile(species, false))
                  if i==0
                    @sprites["p0"].bitmap.blt(0,15,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==1
                    @sprites["p1"].bitmap.blt(100,15,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==2
                    @sprites["p2"].bitmap.blt(200,15,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==3
                    @sprites["p3"].bitmap.blt(300,15,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==4
                    @sprites["p4"].bitmap.blt(0,115,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==5
                    @sprites["p5"].bitmap.blt(100,115,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==6
                    @sprites["p6"].bitmap.blt(200,115,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
                  if i==7
                    @sprites["p7"].bitmap.blt(300,115,pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  end
    
                  tone=Tone.new(-200,-200,-200)
                  if i==0
                     @sprites["p0"].tone=tone
                  end
                  if i==1
                     @sprites["p1"].tone=tone
                  end
                  if i==2
                     @sprites["p2"].tone=tone
                  end
                  if i==3
                     @sprites["p3"].tone=tone
                  end
                  if i==4
                     @sprites["p4"].tone=tone
                  end
                  if i==5
                     @sprites["p5"].tone=tone
                  end
                  if i==6
                     @sprites["p6"].tone=tone
                  end
                  if i==7
                     @sprites["p7"].tone=tone
                  end
                  i=i+1
     
    Last edited:

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • Thanks for the tone info


    I'm basically trying to do similar to what the pokedex does

    i've got it working a long winded way, but i want to make it easier to manage and not have to define each sprite. i know the following displays their sprites, need to find the bit that displays icons instead. i can find the bit that displays if you have a pokemon but not if you just have an dex id

    Ewww....lol, sorry. I'm assuming you're putting all of that code in a loop. It's fine and all, but not really as efficient. You can re-write all of what you just did as simply as
    Code:
    tone=Tone.new(-200,-200,-200)
    x=0
    y=0
    for i in 0...8
      pkmnbitmap=AnimatedBitmap.new(pbPokemonBitmapFile(species, false))
      @sprites["p#{i}"].bitmap.blt(x*100,15+(y*100),pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
      @sprites["p#{i}"].tone=tone
      x+=1
      y+=1 if x>3
      x=0 if x>3
      y=0 if y>1
    end
    Much cleaner don't you think. Is that what you were trying to do? Lol, I still don't understand what you mean. Or are you trying to do a grid based Pokedex? You can apply the same method here, but for the x coordinates you'd need to add additional page variable that will be (page*Graphics.width). That way you'd have proper paging for when you want to scroll between the things. Here let me write you a basic example of how I'd do a simple Pokedex replacement:
    Code:
    k = 1
    for i in 1...650 # will go to 649, which is the gen 5 limit
      k = i if $Trainer.seen[i] #checks to see the number of the last seen pokemon
    end
    tone=Tone.new(-200,-200,-200)
    x = 0
    y = 0
    p = 0
    for i in 0...k # will generate icons for pokemon species 1 to the last seen pokemon
      species = i+1
      pkmnbitmap=AnimatedBitmap.new(pbPokemonBitmapFile(species, false))
      @sprites["p#{i}"]=Sprite.new(@viewport)
      @sprites["p#{i}"].bitmap=pkmnbitmap if $Trainer.seen[species]
      @sprites["p#{i}"].x=(x*100)+(p*Graphics.width)
      @sprites["p#{i}"].y=15+(y*100)
      @sprites["p#{i}"].tone=tone if !$Trainer.owned[species]
      x+=1
      y+=1 if x>3
      x=0 if x>3
      p+=1 if y>1
      y=0 if y>1
    end
    Does this help? This will essentially create a National Pokedex, but you can adjust it for some regional based Pokedex just as easy.

    [EDIT] I amended the code a little. Messed up with the y coordinates of your things. Just a little fix.
     
    Last edited:
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    yeah, they help a lot. What i'm trying to do is when you visit a npc, then npc randomly selects the nation dex id of a random number of pokemon and displays the icons (like in the party and dex, not their sprites) on screen. The tone depends on if the player has seen or caught a species

    The first method is working fine, but is there a way to make it so that i dont need to define x amount of
    Code:
    @sprites["p0"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)

    With the second method, i'm getting
    can't convert AnimatedBitmap into Bitmap

    On the attached image, A is what i have so far, and B is what i want.

    The code at the moment is
    Code:
                for pokemon in encounterList
                  species = pokemon[0]
                  pkmnbitmap=AnimatedBitmap.new(pbPokemonBitmapFile(species, false))
                  #@sprites["p#{i}"]=Sprite.new(@viewport)
                  #@sprites["p#{i}"].bitmap=pkmnbitmap
                  #@sprites["p#{i}"].x=(x*100)+(p*Graphics.width)
                  #@sprites["p#{i}"].y=15+(y*100)
                  @sprites["p#{i}"].bitmap.blt(x*100,15+(y*100),pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
                  if $Trainer.owned[species]
                     tone=Tone.new(0,0,0)
                     caught = caught + 1
                  elsif $Trainer.seen[species]
                     tone=Tone.new(-100,-100,-100)
                     seen = seen + 1
                   else
                     tone=Tone.new(-255,-255,-255)
                  end
                  @sprites["p#{i}"].tone=tone
                  i+=1
                  x+=1
                  y+=1 if x>3
                  x=0 if x>3
                  y=0 if y>3
                end

    versions.png
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    I would simply make each icon be an instance of PokemonSpeciesIconSprite, rather than do stuff with AnimatedBitmaps and overlays and blt. They animate automatically, so long as you call their update methods in your new screen's update method.
     
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    ok, I've got it showing the icon files, but only the last icon is animating, and sometimes the icons disappear after a few seconds or don't show to start with
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • ok, I've got it showing the icon files, but only the last icon is animating, and sometimes the icons disappear after a few seconds or don't show to start with

    That is why you define an X amount of @sprites["p#{i}"]. Having it set up like that, you make sure that the icons don't disappear, as the old ones do not get replaced by the new one. Also you can make all of your icons animated. You don't need to define them manually. And you don't need to have a set amount of icons to display. All that can easily and automatically be done with a for loop.
    Code:
    for i in startindex...endindex
      @sprites["p#{i}"].update
    end
    That is why it's useful giving every icon a unique index ID. And with the for loops it doesn't matter how many sprites you have, as no additional work has to be done. It can create 5 or 100 sprites using the same code, and the same amount of effort.
     
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    i have them set up as
    Code:
    @sprites["icon{i}"]=PokemonSpeciesIconSprite.new(species,@viewport)

    i also have
    Code:
    def pbUpdate
        for i in 0...@total
          @sprites["icon#{i}"].update
        end
      end
    but i get the error
    Message: undefined method `update' for nil:NilClass
     
    Last edited:

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    i have them set up as
    Code:
    @sprites["[COLOR=Red]icon{i}[/COLOR]"]=PokemonSpeciesIconSprite.new(species,@viewport)
    i also have
    Code:
    def pbUpdate
        for i in 0...@total
          @sprites["[COLOR=Red]icon#{i}[/COLOR]"].update
        end
      end
    but i get the error
    Typo spotted.

    I recommend that you don't make an icon for every listed species, because you could have hundreds and that's not necessary. Instead, I would only have as many icons as can fit on screen at once, and change their species accordingly as you scroll through them.
     
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    ok, it seems that even other sprites are disappearing after a while, not just the pokemon icons. I'm not too fussed about them animating, but i'd like to get the disappearing problem fixed

    This is the code so far
    Code:
              for pokemon in encounters
                  species = pokemon[0]
                  # Load mapencounters-iconback
                  back=AnimatedBitmap.new("Graphics/Pictures/mapencounters-iconback")
                  @sprites["back{i}"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
                  @sprites["back{i}"].bitmap.blt(20+(x*100),80+(y*100),back.bitmap,back.bitmap.rect)
                  # Load pokemon icon
                  @sprites["icon{i}"]=PokemonSpeciesIconSprite.new(species,@viewport)
                  @sprites["icon{i}"].x=20+(x*100)
                  @sprites["icon{i}"].y=80+(y*100)
                  # Load not caught icon
                  caughtIcon=AnimatedBitmap.new("Graphics/Pictures/mapencounters-notcaught")
                  if $Trainer.owned[species]
                     caught = caught + 1
                     # If pokemon caught replace not caught icon with caught
                     caughtIcon=AnimatedBitmap.new("Graphics/Pictures/mapencounters-caught")
                  elsif $Trainer.seen[species]
                     seen = seen + 1
                  end
                  @sprites["caught{i}"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
                  @sprites["caught{i}"].bitmap.blt(20+(x*100),80+(y*100),caughtIcon.bitmap,caughtIcon.bitmap.rect)
                  i+=1
                  x+=1
                  y+=1 if x>4
                  x=0 if x>4
                  y=0 if y>4
                end
                @total = i
              end
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    ...Now show us how you're updating your scene. The problem is obviously in def update.
     
    772
    Posts
    13
    Years
    • UK
    • Seen Apr 19, 2024
    Code:
    def update
        pbUpdateSpriteHash(@sprites)
        for i in 0...@total
          @sprites["icon{i}"].update
          @sprites["back{i}"].update
          @sprites["caught{i}"].update
        end
      end
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    You don't need to do all that. You're missing the point of calling everything @sprites["somethinghere"].

    @sprites is a hash, which is a kind of array. It's a group of things, basically. Here, it's all the Pokémon icons and all the mapencounters-iconback graphics (which judging by your video you don't actually have because I can't see them) and all the caught icons. The point is that they're all the same place - they can all be found in @sprites.

    So then what does pbUpdateSpriteHash(@sprites) do? If you can read, you might be able to guess, but you can always have a look for the def pbUpdateSpriteHash and see what its code is. It goes through everything in @sprites and updates each and every one of them. Specifically, it calls the def update for each of those things.

    What you've then proceeded to do is to update all these things again anyway. That's unnecessary, and it's what's making the last icon animate twice as fast. I don't know why the others aren't animating at all, nor why they can disappear after a time, but that's bound to be in some other part of your scripts which you haven't shown us.

    Now, aside from doubling up on your updating, I can also tell you that you don't need to use BitmapSprite for the iconbacks and caught icons. Use IconSprite instead, because it's easier. Also, where are you setting the tone for the Pokémon icons? Since it's not going to change while you're in the screen, you might as well set the tone in def initialize right when you create the icon itself.

    For the sake of not prolonging this thread by not having all the information we need to help you (I'm assuming you don't want to just reveal your entire script), you can PM me with it so I can have a look through. Let me know what this iconback graphic is supposed to be too.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    Earlier I mentioned a typo - an instance of @sprites["icon#{i}"] was missing the # in it. The problem was, desbrina then went and removed the # from all over the place.

    #{blahblah} in a string means to evaluate blahblah and put it there instead. {blahblah} is literally just the text {blahblah} and is entirely different to whatever blahblah actually equals. What the code was doing was making a new set of icons (background, Pokémon and caught icons) but calling them all the same thing each time. This meant that only the last set of icons actually existed, since the previous ones were overwritten, which is why only the last Pokémon icon was animating.

    The moral is: make sure you're typing the correct things. :)
     
    Back
    Top