Game Development Community

Scrolling Text??

by Jackie Hayes · in Technical Issues · 04/07/2003 (1:35 pm) · 4 replies

Has anyone messed around with scrolling text? What I am talking about is text that would start the bottom of the screen and smoothly scroll to the top? I am trying to have information from a text file presented this way in the engine. Kind of like credits at the end of movie.

If anyone could at least point me in the right direction would be appreciated.

Thanks!

MJ....

#1
04/09/2003 (6:54 am)
I know this may be simple to some but ANY help would be appreciated.:)

Thanks!
MJ....
#2
04/09/2003 (8:32 am)
Offhand I can think of a couple of approaches to achieving a sliding/ scrolling effect in Torque. Either: a) use a schedule to continue changing the gui position in script (though personally I'm not a big fan of over-using schedule for effects like that) -- using something along the lines of (and bear with me since it's almost 2am and I'm scripting on the fly):

// Scrolls the gui to a specific point on the screen over a given amount
// of time at a specified update rate, assuming default values for the 
// last two parameters if they arent set...
function GuiTextCtrl::Scroll(%this, %finalPosition, %duration, %update)
{
    // If the duration is omitted, zero, or less, assume a default value of 1.
    if (%duration $= "" || %duration <= 0)
    {
        %duration = 1;
    }
 
    // If the update is omitted, zero, or less, assume a default value of 10.
    if (%update $= "" || %update <= 0)
    {
        %update = 10;
    }
 
    // Get the current X and Y positions.
    %this.scroll_initial_X = getWord(%this.getPosition(), 0);
    %this.scroll_initial_Y = getWord(%this.getPosition(), 1);
 
    // Set up the desired position to scroll to.
    %this.scroll_desired_X = getWord(%finalPosition, 0);
    %this.scroll_desired_Y = getWord(%finalPosition, 1);
 
    // Determine the starting time of the scroll.
    %this.scroll_startTime = $Sim::Time;
 
    // Set how long the scroll takes.
    %this.scroll_duration = %duration;
 
    // Set the number of milliseconds to use for the schedule.
    %this.scroll_scheduleDelay = %update;
 
    // Begin the scroll update.
    %this.ScrollUpdate();
}
 
 
// Update the scroll effect...
function GuiTextCtrl::ScrollUpdate(%this)
{
    // Get a 0 - 1 value used to determine how far through the scroll we are...
    %mix = ($Sim::Time - %this.scroll_startTime) / %this.scroll_duration;
 
    // Calculate the new x and y coordinates of the gui.
    %newX = %this.scroll_initial_X + ((%this.scroll_desired_X - %this.scroll_initial_X) * %mix);
    %newY = %this.scroll_initial_Y + ((%this.scroll_desired_Y - %this.scroll_initial_Y) * %mix);
 
    // Couldnt see a setPosition function in the head, so it looks like its resize... bleh.
    %this.resize(%newX, %newY, getWord(%this.getExtent(), 0), getWord(%this.getExtent(), 1));
 
    // If weve still got time to go, schedule an update...
    if ($Sim::Time < %this.scroll_startTime + %this.scroll_duration)
    {
        %this.schedule(%this.scroll_scheduleDelay, "ScrollUpdate");
    }
    else // Otherwise...
    {
        // Once again, no setPosition so Im using resize...
        %this.resize(%this.scroll_desired_X, %this.scroll_desired_Y, getWord(%this.getExtent(), 0), getWord(%this.getExtent(), 1));
    }
}

... then just call it on the appropriate gui object...

// Scroll to 0,0 on the screen over a second using the default 10ms schedule.
MyTextGUI.Scroll("0 0");

Alternatively, specify how long the scroll takes...

// Scroll to 400, 300 on the screen over 4.0 seconds using the default 10ms schedule.
MyTextGui.Scroll("400 300", 4.0);


... or better yet, actually delve into the code and write/ add functionality to do it. For the project I'm working on we've got an effects class for text and graphics that has a lot of the old standard 2D effects (wave, water ripples, lens, sliding, fading, pixelation, etc) in it. Maybe you could develop something similar.

Edit: Stupid formatting. =(
#3
04/09/2003 (9:03 am)
Thanks alot Daniel!!! This is GREAT! I do appreciate it very much.:)
I just was not sure which would be the best way to go. I think you just answered my question and saved me a TON of time.

Thanks man!
MJ....
#4
04/09/2003 (9:12 am)
Bordom achieves many things... Not all of them good. =)