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..

https://www.youtube.com/watch?v=3YZWja4z7sk

It works by creating a surface and a text object for each scrolling text. Use is basically:
Code: [Select]
fe.load_module("objects/scrollingtext");
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):
https://github.com/liquid8d/attract-extra/tree/master/modules/objects

A sample layout is available there as well:
https://github.com/liquid8d/attract-extra/tree/master/layouts/sample_objects_scrollingtext

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.font="time";
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.
IE:
one
two
three

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.

Thanks.
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.

https://www.youtube.com/watch?v=rzErov3MQDE

http://forum.attractmode.org/index.php?topic=1558.0
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.

https://www.youtube.com/watch?v=rzErov3MQDE

http://forum.attractmode.org/index.php?topic=1558.0

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 box.like is it a romlist or a gamelist that u need to edit or something?
Title: Re: ScrollingText module
Post by: arthurvalenca on June 22, 2018, 07:07:09 AM
Hello friends, I'm having trouble making the text scroll up, even changing the code it continues to move left, someone could help me with this

Code: [Select]
fe.load_module("objects/scrollingtext");
local scroller = ScrollingText.add( "[OVERVIEW]", 25, 50, fe.layout.width - 25, 75, ScrollType.VERTICAL_UP );

//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;

PS: It has been changed in all ways to VERTICAL_UP, but still continue to the left, please help me.
Title: Re: ScrollingText module
Post by: Dal1980 on June 26, 2018, 06:28:32 PM
Hi arthurvalenca

I would suggest trying the sample https://github.com/liquid8d/attract-extra/tree/master/layouts/sample_objects_scrollingtext and altering that to see if you still have the problem.

If the problem goes away using the sample layout file then I would suspect either something happening in the code before your scrolling text or some issue with updating the file via FTP/Samba (check to make sure your changes are being wrote as I've fell into this trap before. I've also had crazy times where I was updating the wrong file too but that's just my world probably ;D).

Hope this helps
Title: Re: ScrollingText module
Post by: arthurvalenca on June 27, 2018, 01:07:47 PM
Thank you! I was able to correct the problem of the text going up, another problem that appears and that in the folder overview contains a .cfg file with a text of the description of the game, but the scroll is only reading three words, somebody knows how I can increase the number of words can the scroll read?
Title: Re: ScrollingText module
Post by: Dal1980 on June 27, 2018, 03:02:21 PM
Don't know if this helps but I ended up having an annoying problem with sending values created from functions over to the scrollingtext. It would either cull any text after the function call even if I had stored the value in a variable before including it in the string or stop all other variables from being populated and somehow write over existing string with a populated value much like how the insert key works on the keyboard. My only guess was that it picked up a new line "/n" or carriage return "/r" (which doesn't explain everything anyway) somewhere but even after sanitising data it still seemed to be an issue. I ended up leaving it alone and just working around the problem.

Code: [Select]
    //function simpleCat just spits out the first cat name from catver.ini
    function simpleCat( ioffset ) {
      local m = fe.game_info(Info.Category, ioffset);
      return split( m, " / " )[0];
    }

    local txtMarquee = "*** [Title] *** Manufactured by [Manufacturer] in [Year] *** Listed Category: [!simpleCat]";
    local scroller = ScrollingText.add( txtMarquee + " ***", flw*0.450, flh*0.001, flw*0.370, flh*0.055 );

    //the above produces something like the following
    //*** A game title *** Manufactured by SomeCo in 1980 *** Listed Category: Sports
    //notice even concatenating the extra 3 **** at the end does not show

    //but if I do this
    local txtMarquee = "*** [Title] *** Listed as [!simpleCat] and Manufactured by [Manufacturer] in [Year] *** Insert Coin";
    local scroller = ScrollingText.add( txtMarquee + " ***", flw*0.450, flh*0.001, flw*0.370, flh*0.055 );
    //I get weird results
    //*** A game title *** Listed as Sportsufactured by in *** Insert Coin ***
    //I've lost my [Manufacturer] and [Year] magic tokens


I don't think this will be a fix in your script, you may need to start pulling the scrollingtext module apart. Maybe someone could shed some light on this but for me I went with a cheap workaround for now.
Title: Re: ScrollingText module
Post by: arthurvalenca on July 11, 2018, 07:31:53 PM
I had some result in scrolling the text up but still is not expected, it follows the scrolling code of the text as the photo shows, does anyone have a hunch?   

(http://i67.tinypic.com/2b18uo.png)

Code: [Select]
#------------------------------------------Overview---------------------------------------

::OBJECTS <- {
    logo = fe.add_text("[Overview]", flx*0.422, fly*0.85, flw*0.509, flh*0.56 ), 
}

local pac = {
    when = Transition.ToNewSelection,
property = "y",
start = fly*0.670,
end = fly*0.350,
tween = Tween.Linear,
time = 30000,
delay = 0,
loop = true
 }

animation.add ( PropertyAnimation( OBJECTS.logo, pac ) );
OBJECTS.logo.font = "zektonbo";
OBJECTS.logo.set_rgb ( 255, 255, 255 );
//OBJECTS.logo.set_bg_rgb ( 0, 80, 220 );
OBJECTS.logo.charsize = 14;
OBJECTS.logo.word_wrap = true;
OBJECTS.logo.align = Align.Centre;
Title: Re: ScrollingText module
Post by: Steven Campoli on October 08, 2018, 08:35:53 PM
How do I use this?
I have the module but how do I make it work?
I also pasted it in the plugins folder and enabled it but still doesn’t work?
Title: Re: ScrollingText module
Post by: jedione on October 09, 2018, 06:05:15 AM
here is one i use a theme....
Code: [Select]
// srolling text game title
local scroller1 = ScrollingText.add( "[Title]", 0, 0, 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 = 36;
scroller1.set_pos( 805, 208, 311, 30 );
scroller1.settings.speed_x = 1.9;
//fixed_width = 1000;
//scroller.settings.delay = 250;
//scroller.settings.loop = 5;

uncomment the font time and replace with your one font....peace
Title: Re: ScrollingText module
Post by: Steven Campoli on October 09, 2018, 05:17:48 PM
Hey, thanks for the reply

Where do I paste this?
In the layout.nut file?
Title: Re: ScrollingText module
Post by: jedione on October 09, 2018, 07:15:57 PM
well yes ,, the layout.. :o
Title: Re: ScrollingText module
Post by: Steven Campoli on October 09, 2018, 07:26:57 PM
Ok I’ll try this and get back to you tomorrow :)
Thanks again
Title: Re: ScrollingText module
Post by: Steven Campoli on October 10, 2018, 08:37:12 AM
i pasted it in the layout file but nothing is happening...is thier something im missing? i just want the title and filters to scroll...