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.

Text fading in and out?

I am working on a new VX script, my first in a long time, and I need to
be able to make a piece of text fade in and out.

I have the text drawn in a bitmap, which is held in a sprite.

Does anyone know how to do this?
 
All you need to do is adjust the .alpha of the bitmap.font.color and then refresh it, here I'll do a quick example...

Code:
def update

  c = self.bitmap.font.color

  @fade_out = false if c.alpha == 255 && @fade_out

  @fade_out = true  if c.alpha ==   0 && !@fade_out

  c.alpha += (@fade_out ? -1 : 1)

  self.bitmap.clear_rect(0, 0, 64, 32)

  self.bitmap.draw_text(0, 0, 64, 32, "Text")

  super

end

I didn't test it but something along those lines should work.
 
It doesn't work at all, actually.

I made this based off your code, but it doesn't work either:

[rgss] 
  def update_start
    @fade_out = false if @start.opacity == 255 && @fade_out
    @fade_out = true  if @start.opacity ==   0 && !@fade_out
    @start.opacity += (@fade_out ? -5 : 5)
  end
 
[/rgss]
 
You can use the .opacity property of Sprite for making a fade in/fade out effect.
Example:
Code:
s = Sprite.new

s.bitmap = Bitmap.new(100, 32)

s.draw_text(0, 0, 100, 32, 'Example', 1)

s.opacity = 0

# Fade in

loop do

  Graphics.update

  s.opacity += 1

  break if s.opacity == 255

end

Graphics.wait(60) # Wait 1 sec

# Fade out

loop do

  Graphics.update

  s.opacity -= 1

  break if s.opacity == 0

end

s.bitmap.dispose

s.dispose
 
I did it!

My code is:

[rgss] 
  def update_start
    @fade_out = true if @start.opacity == 255
    @fade_out = false if @start.opacity == 50
    if @fade_out
      @start.opacity -= 5
    else
      @start.opacity += 5
    end
  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