Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: liquid8d on July 28, 2015, 08:20:56 PM

Title: ScrollingText module
Post by: liquid8d on July 28, 2015, 08:20:56 PM
Hey all... put together this module because I wanted scrolling text. Still a bit of a WIP, so you'll probably see some goofy things, but feel free to play around with it and give me any feedback..

It works by creating a surface and a text object for each scrolling text. Use is basically:
Code: [Select]
local scroller = ScrollingText.add( "[Title]", 25, 50, fe.layout.width - 25, 75, ScrollType.HORIZONTAL_LEFT );

//there is a couple wrapper functions for color:
scroller.set_rgb( 255, 0, 0 );  //the text color
scroller.set_bg_rgb( 0, 0, 0 ); //the surface color (uses a pixel.png to color the surface)
//scroller.set_pos( 0, 0, 100, 100 ); //the surface x, y, w, h

//you can access the surface and text objects directly
//scroller.surface <- the surface
//scroller.text <- the text object

//There are also some settings:
scroller.settings.delay = 500;
scroller.settings.loop = -1;

The module is in my github in modules/objects (make sure to grab the .nut and the folder and put it in modules/objects):

A sample layout is available there as well:

For details on use, look in the modules/objects/scrollingtext.nut file
Title: Re: ScrollingText module
Post by: jedione on October 30, 2016, 12:44:24 PM
thanks this is great

Q: is their a way to change the Font?
Title: Re: ScrollingText module
Post by: liquid8d on October 30, 2016, 01:35:35 PM
I sent a direct msg to you, but I'll post here in case anyone is interested:

The scroller object you get is a custom object (composed of multiple objects, a surface and the text object that scrolls). You can access the text object from scroller.text so any properties of an FeText object can be modified there:

scroller.text.font = "font";
Title: Re: ScrollingText module
Post by: jedione on October 30, 2016, 05:21:20 PM
thanks will be trying this.....
Title: Re: ScrollingText module
Post by: jedione on October 30, 2016, 06:18:25 PM
so i got it working and is good i also made it work with animation...but with animation
it needs to start behind something and end behind something,,   were as the scrollingtext module
it goes right off the ends hidden witch is good ,  i can put it in tighter spots !

Q:  using "ScrollType.HORIZONTAL_LEFT"  after it disapers out the end of the surface
it takes about 7 sec before it will show up on the right side again for a loop.
 How can i change this so as the last tail end is going of the surface as it is starting at the other end again?

heres both codes..

//*****scrolingtext module******

local scroller1 = ScrollingText.add( "[Title]", 25, 50, 300, 45, ScrollType.HORIZONTAL_LEFT );

scroller1.set_bg_rgb(0, 220, 0, 150);
scroller1.set_rgb( 255, 0, 0 );
scroller1.text.font = "time";
scroller1.text.charsize = 25;
scroller1.set_pos( 200, 500, 400, 30 );

//*****scrolling text anime********

::OBJECTS <- {
    logo = fe.add_text("[Title]", 850, 202, 195, 050 ), 

local pac = {
    when = Transition.StartLayout ,property = "x", start = 1150, end = 580, tween = Tween.Linear, time = 7000, delay = 000, loop = true

animation.add( PropertyAnimation( OBJECTS.logo, pac ) );
OBJECTS.logo.set_rgb( 255, 0, 0 );
OBJECTS.logo.charsize = 28;

thanks bro...
Title: Re: ScrollingText module
Post by: liquid8d on October 31, 2016, 11:03:39 AM
So the problem here is when I wrote this, there wasn't a way to get accurate length in pixels of the text, based on the font and text size. By default it attempts to guess at the length based on the length of the text and the charsize set. This might not be accurate especially if you are using magic token variables, so you might have to set a fixed width of the actual text object using scroller.fixed_width = ? - Of course, then it may cut off longer text so you will have to decide what works best for you.

There is supposed to be a way now in AM to get a measurement, but when I was testing it I couldn't get it to work properly.
Title: Re: ScrollingText module
Post by: jedione on October 31, 2016, 09:07:40 PM
thank you..

i noticed the longer the the text the longer the cycle....ok

Q: is their a way when using the "VERTICAL_UP" to have it do
multiple lines.

instead of,,,,   one two three.
Title: Re: ScrollingText module
Post by: bjose2345 on June 18, 2017, 09:34:31 AM
Sorry for resurect this very old thread, but there is a way to do what jedione is asking, multiline "VerticalUP"? There is a way to emulate the same behaviour like in emulastation, where if the text is longest that a certain amount of characters, space, etc, Automatically after a while start to scroll up.

I know maybe we can do this with an animation (a delay to start and some extra var to check the length of the text to call it), but well still I have the problem with a multilne text from a [overview] call.

Title: Re: ScrollingText module
Post by: liquid8d on June 18, 2017, 07:21:51 PM
As I mentioned before, there was no way to measure text width/height which you would need to accurately do something like that. With different fonts and font sizes, using number of characters in a string doesn't tell you much. You don't know if the text fits within its constraints, so you don't really know whether to scroll or not. You could set a limit of characters possibly, but with different fonts and font sizes, I don't think it'd be all that reliable.

For reliable scrolling, I think this is something that needs to be added in for text objects - or at least, provide a way in squirrel to accurately measure the virtual width/height of text with a specific font and size.

I'm going to look at some additional objects soon, so I might revisit this at that point. If I see raygun around, I might pester about it a bit more - since it is a lacking feature that is needed :)
Title: Re: ScrollingText module
Post by: bjose2345 on June 18, 2017, 09:58:44 PM
First i want to give you the thanks, for all your awesome work liquid8d, you are an amazing person. Second i made some progress with the multiline part,  have 2 options:

1.Set the word_wrap from obj._text = true; but with some strange behaviour (like no real scroll, only by default scroll to horizontal and to the left but the multiline its shows)

2.I add the next piece of code in your scrollingtext.nut (and actually works, but like  you said there is no way to adjust the length, You need to put a random number that will make it look good, but with some strange behaviours too, sometimes  )

//obj._text = ScrollingText.actual_text(obj, var); //instead of call this part
obj._text = ScrollingText.chunk(obj, 5,  var); // i call this

chunk = function (str, n, var)
      local ret = [];
      local i = 0;
      local e = 0;
      local len;
      local actual = ScrollingText.actual_text(str, var);   /* inside actual_text you need to add a reference for the [overview] magic token*/
      len = actual.len()      
      for(i; i < len; i += n) {
         e += n;
         if (e >= len)    e = len;         
         ret.push(actual.slice(i, e)+"\n"); /* i transform the string by adding a break line every n characters */
      return ret;

well and one last thing, dunno if is because Im using the conveyor.nut in my theme, but when the Transition.FromOldSelection is call from the transition_callback function (when you hit some of the borders of the carousel and need to draw a new image, the [overview] text just Disappears, Nothing is displayed, only the first letter  :o )
Title: Re: ScrollingText module
Post by: qqplayer on June 21, 2017, 10:09:43 AM
I made a this , I know isīnt the right way , but works quite good.
Title: Re: ScrollingText module
Post by: bjose2345 on June 21, 2017, 11:22:36 PM
I made a this , I know isīnt the right way , but works quite good.

this is a great idea Thanks qqplayer, you are a lifesaver  :)
Title: Re: ScrollingText module
Post by: mikeandbirgit on July 11, 2017, 09:36:51 PM
ok dumb question but how do you get the game info text inside the is it a romlist or a gamelist that u need to edit or something?