First of all, you need to make 3 "actions" to your script.
First Script is following:
Code: Select all
screenwidth = 640
scrollspeed = 100
y = 200
SetFont(#SANS, 50)
CreateTextObject(1, "my text to scroll", {color=#BLUE})
WidthOfText = GetAttribute(#TEXTOBJECT, 1, #ATTRWIDTH)
x = 50 + screenwidth
StartTimer(1)
continuescrollloop=False
Repeat
timerloopcontinue = False
Repeat
timepassed = GetTimer(1)
If timepassed => 5 Then timerloopcontinue = True
Until timerloopcontinue=True
ResetTimer(1)
x=x - (100 * (timepassed/1000))
If x < -50 - widthoftext Then x = 50 + screenwidth
ShowLayer("scrolltext", x, y)
Until continuescrollloop=True
RemoveLayer("scrolltext")
First line is setting Screenwidth. This is important to be right, or scrolling will start/end at wrong locations. Idea is that if you are using for example 1920x1080 display (HD resolution) then you will mark Screenwidth as 1920.
You can try putting your page to 1920x1080 and yet use screenwidth of only 640. Especially if text amount to scroll is small amount. you might actually undertand this code better when you see it working wrong.
Next three lines are up to you to put how ever you like.
Speed is the scrolling speed. This speed refers to amount of pixels it will move in one second.
y refers to where in up-down sense will the screen display. 0 will be top, and greater the number, more down it will be scrolling. If number is too big, it will be outside of display. If you dont understand it, start with 100, and then make the number bigger or lower to try out where it ends.
SetFont command chooses both the font to be used for your text, as well as its size.
After these four lines, there happens several lines that are happening automatically based upon what you did before. Only thing to take care of in here, is in "CreateTextObject" that "Color" part. You can use one of the usual clors like #WHITE, #BLUE... or you can use more accurate "RGB(255, 255, 255)" which will separately decide how much Red, Green, Blue the color will have (0-255, where 255 is max) or you could even go to ARGB(255, $FFFFFF), in which case first number sets how transparent that color is, while the $FFFFFF is same as RGB, except in this case it is in different form where you are using two number-alphabets to each R, G and B. From numbers between 0 - F. by other words, ...7, 8, 9, A, B,C...
This part you dont need to undertand, but I am explaining anyway what is happening there.
CreateTExtobject is where your actual scrolling text text is created.
After this I am letting Hollywood check out the total width of that scrolling text, a Long text could well result in even 100 000 pixels.
after this i determine the x to start from location 50 + screenwidth. This means that location is 50 pixels out of screen to the right. You could leave this (50) out, it is basically sort of a buffer. That this way the scroll text wont appear to screen instantly. If you leave that 50 out,then screen will appear to screen faster. On the other hand, make 50 bigger, and it will take longer for text to appear. It is a matter of taste.
Displaytextobject acvtually makes the text to appear to screen (although at beginning it is outside of screen). This text becomes so called layer, and at this point comes problem. How do we know this layers ID so we can control it later?
Next two lines, GetAttribute and SetLayername deal with this. We are getting its ID and giving name to that ID so we can later refer to it by name.
Now comes the final part before going to action. "StartTimer(1)" this one starts a timer which is being used later to make it run at same speed on every machine.
We are now entering Repeat-until loop. One which says it will continue going through those lines betweem repeat and until, until variable "continuescrollloop" becomes TRUE. This is why it is first set to FALSE, so it keeps going between these lines.
These loop consists of two parts. First of all, another loop, which takes care of the timer a bit. This second loop is not necessary for slower machines, but if there is fast machine enough, then without this loop. there is potential problem. For it is possible that the repeat-until will be gone through so fast, that not even 1 time unit goes from timer. In this case, it will record timepassed as being 0. If we then move scrolltext based upon. Speed * 0 it results in 0, meaning it wouldnt move.
In this second loop it is being checked that at least 5 time units have went on, beforfe moving forward to the second part.
Second part is quite simple. First it is basically doing x=x-1. Although bit more complicated way, since in this case it doesnt simply minus 1, but it checks how much time have passed, and what is the speed, and based upon those two factors it decides how much x should be decreased.
Then it checks if x is already more to minus than is the width of the text, since if that is the case, then it means text have already fully scrolled from right to left and it is time to move this text back to right side, so it will start it from beginning.
Then finally we display the "scrolltext" layer to its new location, which is x, y, and as we just made the x bit different that before, it looks like text is scrolling.
as last, when it get out of the loop, it will remove that scrolltext, so it doesnt keep displaying elsewhere.
SECOND ACTION needs to be something that keeps the page staying. It can be your regualr page waiting for interaction, but in this example case lets use "WaitForRightMouse". Now it wont move past this until Right Mouse Button is pressed.
THIRD ACTION is put under SECOND ACTION, and will be "Run Code" again. This time with only one line:
Code: Select all
continuescrollloop=True
Notice. FIRST ACTION needs to come before SECOND and THIRD.
SECOND ACTION (or whatever that keep the page still) needs to be before THIRD.
FIRST ACTION needs to be Asynchronous Action (just tick the box). This means that it keeps running along with the rest at same time, instead of being executed first before going to next script.
One more thing, hopefully you dont need to understand this, but you might in case this doesnt work.
This Line:
Code: Select all
Local layerid = GetAttribute(#BGPIC, 1, #ATTRLAYERS)
However, there is alternative way.
You can remove all following lines of code:
Code: Select all
SetFont(#SANS, 50)
CreateTextObject(1, "my text to scroll", {color=#BLUE})
DisplayTextObject(1, x, y)
Local layerid = GetAttribute(#BGPIC, 1, #ATTRLAYERS)
SetLayerName(layerid, "scrolltext")
I would actually even recommend douing it this way, since this way you can see in designer already the text and change it etc. Will be easier for you in the end. Just harder to explain.
Oh, and do notice. This TEXTOBJECT needs to be created before FIRST ACTION, since that textobject needs to exist already by that time, so its width can be calculated.
hope this helps.