Scripts:Textbox fade in

From OHRRPGCE-Wiki
Jump to navigation Jump to search

There are many different ways to create a textbox with text that fades in. The scripts given here achieve this the way it is done in Sword of Jade: by using normal textboxes which had the font colour set to a spare colour on the Master Palette. The old default master palette had several spare colours, but the latest one doesn't, which might be a problem. You could also use plot:lookup slice and plot:set text color to modify the text box's text colour directly instead of the master palette.

The text colour should start out the desired final colour, then a script modified the master palette so that colour is black, displays the textbox and fades that colour in. The fade out is in a separate script so that you can choose how to wait before fading out.

A disadvantage is that you still see the textbox displayed line-by-line, however the fade in is (by default) much slower than this, so it doesn't look too bad.

For example, to display text box 100, which is set to use text colour 239, and display it until the player presses a key:

fade in textbox (100, 239)
wait for key (anykey)
fade out textbox (239)

Each script takes an optional argument, the time to fade out, in ticks. For example, to fade in the box slowly, wait for 5 seconds, and fade out:

fade in textbox (100, 239, 40)
wait (90) # 90 ticks is about 5 seconds
fade out textbox (239, 40)

Script Code[edit]

# a default fade length (number of ticks) of 20, equal to roughly a second
script, fade in textbox, box, color, fade length = 20, begin
  variable (i, red, green, blue)

  # this will be the final color, read it for reference
  red := read color (color, color:red)
  green := read color (color, color:green)
  blue := read color (color, color:blue)

  # set the text colour to black
  write color (color, color:red, 0)
  write color (color, color:green, 0)
  write color (color, color:blue, 0)

  #prevent the player from skipping the box normally
  suspend box advance

  show text box (box)
  # a slight pause to let the textbox display, you can modify or remove this if you want
  wait (5)

  # fade in over 20 ticks (about 1 second)
  for (i, 0, fade length) do (
    write color (color, color:red, red * i / fade length)
    write color (color, color:green, green * i / fade length)
    write color (color, color:blue, blue * i / fade length)
    update palette
    wait
  )
end

script, fade in textbox, color, fade length = 20, begin
  variable (i, red, green, blue)

  # the box is totally faded in, so can read the color
  red := read color (color, color:red)
  green := read color (color, color:green)
  blue := read color (color, color:blue)

  # this is the same loop as before, but in reverse
  for (i, fade length, 0, -1) do (
    write color (color, color:red, red * i / fade length)
    write color (color, color:green, green * i / fade length)
    write color (color, color:blue, blue * i / fade length)
    update palette
    wait
  )

  # have to reset this!
  resume box advance
  advance text box

  # reset the text color for next time
  reset palette
  update palette
end