Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

another loop problem of mine

so im having issues with the math being too complex in this loop of mine..well the loop is pretty simple, but checking for the x and y coords of each icon is. so here is the loop im using:
[rgss]for i in @index...@files.size
      #stops drawing icon once they reach edge of window
      if (@total_length+RPG::Cache.icon("Towns/"+@files).width) > 465
        next #stops the drawing of icons
      else  
        bitmap = RPG::Cache.icon("Towns/"+@files)
        self.contents.blt(@total_length+10,14,bitmap,Rect.new(0,0,bitmap.width,bitmap.height))
        @total_length += (bitmap.width+10)
      end
    end
 
[/rgss]
@index is which index to start at to cycle through all the options
28vfuoz.jpg


so my problem is i can easily get the x and y coords from where i clicked, but because not all icons are the same size and such as you can see if i simply run loops to check all the x and y coord of icons/buttons id quickly freeze up the system, was hoping some one had a better idea on how to check where i clicked
 
I made an assumption that the icons were all "relatively" similar in size...
The icons can be different sizes, just use the largest size as a baseline, and space all of the icons that distance plus a small margin apart.
i.e. if your largest icon is 32x32, you might space them all 36 apart. If you have a 24x24 icon, you just shift it over & down an extra 4 pixels.
That way the 'placeholders' are all the same size, and your mouse position logic becomes much simpler.
 
thanks brew, but this is for my interactive world map script, so i have to guess how big the biggest will be that the user will use :) lol ether way you still gave me an amazing idea to simple down the math thanks :)
 
here is my final solution. works 1000 times better then what i was using thanks brew!!!! only kills 2 fps when i click so im happy
[rgss]  def click(x,y)
    if y > 120 && y < 210
      for i in 0...7
        if x > (51+(i*40)) && x < (90+(i*60))
          return @files[@index+i]
        end  
      end  
    end  
    return "No Icon Selected"
  end
 
[/rgss]
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top