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.

Need help with animated menu buttons

I decided once again to dive back into the world of RGSS again. I am programming a menu completely from scratch to resemble the old shining force style menu. I have it nearly completed but I am stuck on one little thing. I want the menu to be animated in that when you press the key left, right , up, down it moves to that desired button and it begins to animate. I have to pictures for each of the animation. What would be the best course of action.

what it does is it shows the one picture, waits a few frames and changes to another picture, waits again and goes back to the first picture which then repeats until the person presses the key

would I use a for loop, or a regular loop to get the pictures to simulate an animated button? I understand coding but Ruby is a little foreign to me.
 

khmp

Sponsor

I'm sorry... What was that? I was mesmerized by the gif... Animated buttons?

Code:
class ShiningForce_Menu
  def update
    ... other code

    @timer = 0 if @timer.nil?

    case @timer
    when 0...(Graphics.frame_rate * 2)
       @sprites[self.index].bitmap = RPG::Cache.picture(picture1)
    when (Graphics.frame_rate * 2)...(Graphics.frame_rate * 4)
      @sprites[self.index].bitmap = RPG::Cache.picture(picture2)
    else
      @timer = 0
    end
    @timer += 1

    ... other code
  end
end

The basic gist is that you have a timer that based on where it is along the timeline swap the image to what it needs to be. Doing it through the cache like that isn't expensive. I think that's what you were suggesting but if it isn't I apologize. You could alternatively count to two seconds toggle a boolean and change the image.

Code:
class ShiningForce_Menu
  def update
    ... other code

    @swap = true if @swap.nil?
    @timer = 0 if @timer.nil?

    if @swap && @timer == 0
      @sprites[self.index].bitmap = RPG::Cache.picture(picture1)
      @swap = false
    elsif !@swap && @timer == 0
      @sprites[self.index].bitmap = RPG::Cache.picture(picture2)
      @swap = true
    end

    @timer += 1

    @timer = 0 if @timer >= (Graphics.frame_rate * 2)

    ... other code
  end
end

There's actually probably a ton more ways this could be done. Once input is received change the picture back to whatever it was when it was inactive.

Good luck with it SamusK! :thumb:
 

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