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.

Display [###] @ [Variable X]/[Variable Y], then fading

Is there anyone who could possibly make me a script that says:

write.text = "\v[0020]"
position.be = [variable X]/[variable Y]
font = arial
color = white
move.text upwards while...
fade.text @ 40 frames

It's for an evented battle system I'm working on. Calling the script whenever damage or healing is delt on a hero or enemy. I'm still learning how to script and if you could write this for me I would learn from it. It would help me a lot. :yes:

I just need it to display the value of a variable in text at a given X and Y coordinate.
 
Something like this?
Code:
class Window_Display < Window_Base

  def initialize(x, y)
    super(x, y, 160, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @time = 0
  end
  
  def refresh(text, font, color)
    contents.font.name = font
    contents.font.color = color
    contents.clear
    contents.draw_text(4, 0, 120, 32, text)
    @time = 40
  end
  
  def update
    if @time > 0
      @time -= 1
      if @time == 0
        self.contents.dispose
        self.dispose
      end
    end
  end
end


class Interpreter
  
  alias upd_new update
  
  def display_window(x, y, text, font = 'Tahoma', color = Color.new(255, 255, 255))
    @window = Window_Display.new(x, y)
    @window.refresh(text, font, color)
  end
  
  def update
    @window.update if @window && ! @window.disposed?
    upd_new
  end
end


To test it... type this on the Call Script command:
Code:
display_window(32, 32, 'This works!', 'Impact')
 
Hmm...

Code:
class Scene_
  alias_method :seph_spritethingies_scnx_main, :main
  alias_method :seph_spritethingies_scnx_update, :update
  def main
    @sprite_thingies = []
    seph_spritethingies_scnx_main
    @sprite_thingies.each {|x| x.dispose unless x.disposed?}
  end
  def update
    @sprite_thingies.each do {|x|
      if x.opacity == 0
        x.dispose
        x = nil
        @sprite_thingies.delete(x)
        next
      end
      x.opacity -= 5
    end
    seph_spritethingies_scnx_update
  end
  def create_sprite_thingy(text, x, y)
    s = Sprite.new
    s.x, s.y = x, y
    dummy = Bitmap.new(32, 32)
    tw = dummy.text_size(text).width
    b = Bitmap.new(tw, 32)
    b.draw_text(0, 0, tw, 32, text, 1)
    s.bitmap = b
    @sprite_thingies << s
  end
end

Ok. Now lets say you want to do this in battle, copy that script and change Scene_ to Scene_Battle. Do it for whatever scenes you want this script to be used for.

Then, when you are in your scene, use the script command with :
Code:
$scene.create_sprite_thingy(text, x, y)

Replace text with 'your text here' and x and y with your coordinates.

Not tested, so let me know if it doesn't work.


Haha. Slipknot beat me to it.
 
Doesn't seem to, Seph. I don't understand what you mean by change the scene_. I get it though, there is scene_map, scene_end, etc. I tried those too but still gave me a syntax error. But thats okay though.

Slipknot yours works just fine! Thank you guys so much for your help! you have no idea how much this means to me. You have my blessing.
edit: Except for one thing. How do I place a variable inside "display_window(32, 32, 'This works!', 'Impact')"?
 
Awesome. Totally sweet. 8-) Thanks a ton

See, im even learning how to script myself now. I figured out that if I put Color.new(200, 255, 200)) at the end of the Call Script it will let me change the font color.

Code:
display_window($game_variables[1], 
$game_variables[2], 
$game_variables[1].to_s, 
'Tahoma', Color.new(30, 255, 250))

and I also figured out how to fade the text by adding a line into this part of the script

Code:
  def update
    if @time > 0
      [B]self.contents_opacity -= 6[/B]
      @time -= 1
      if @time == 0
        self.contents.dispose
        self.dispose
      end
    end
  end
end

Now I'm working on trying to get the text to move from one place to another while fading.

edit: hehe scripting is fun. I just added self.oy += 1 and it moves!
 
Take a look at this script now. The text moves up but it gets cut off by the window half-way through. I've tried enlarging the window but it isn't making a difference.

Edit: Figured it out. Just changed the values of whats in red

Code:
class Window_Display < Window_Base

  def initialize(x, y)
    super(x, y, 160, [color=red]64[/color])
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0 # opacity of text window
  end
  
  def refresh(text, font, color)
    contents.font.name = font
    contents.font.color = color
    contents.clear
    contents.draw_text(4, [color=red]0[/color], 120, 32, text)
    @time = 43 # amount of frames before text is deleted
  end
  
  def update
    self.contents_opacity -= 6 # changes the rate the text fades
    self.ox += 0 # changes the speed and direction text moves in horizontally
    self.oy += 1 # changes the speed and direction text moves in vertically
    if @time > 0
      @time -= 1
      if @time == 0
        self.contents.dispose
        self.dispose
      end
    end
  end
end


class Interpreter
  
  alias upd_new update
  # if below values are ommited in call script, will use below values as default
  def display_window(x, y, text, font = 'Tahoma', color = Color.new(255, 255, 255))
    @window = Window_Display.new(x, y)
    @window.refresh(text, font, color)
  end
    def update
    @window.update if @window && ! @window.disposed?
    upd_new
  end
end

Code:
display_window($game_variables[1], 
$game_variables[2], 
$game_variables[3].to_s, 
'Tahoma', Color.new(255, 255, 255))
 

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