Log In
Sign Up and Get Started Blogging!
JoeUser is completely free to use! By Signing Up on JoeUser, you can create your own blog and participate on the blogs of others!
Project: DesktopX
Scripts, tutorials, and general Desktop X help
Scrolling Text - a step by step tutorial
Intermediate
Published on January 3, 2007 By
sViz
In
DesktopX Tutorials
SCROLLING TEXT
This is a step by step tutorial on how to scroll an object. You can use a regular text object to test out this tutorial
Step 1 get the object moving
Step 2 tell the object where to stop
Step 3 repeat
Step 4 downsize, scroll within a small space
Step 5 feel free to get creative
All you need to do is create objects, name them, and insert the scripts in this tutorial.
STEP 1 - Making an object scroll
Make a text object.
Go to the script of your text object and insert this script. (NOTE: The object will keep scrolling off the screen, don't panic.)
Sub Object_OnScriptEnter
'--Set the starting position in the middle of your screen.
object.top = system.screenheight/2
object.left = system.screenwidth/ 2
‘—Set a timer
object.settimer 1, 10
End Sub
Sub object_ontimer1
'--Move object back 2 pixels everytime the timer fires
object.left= object.left - 2
End Sub
STEP 2- Giving your object boundaries
We want to stop the object when it reaches the edge of the screen.
Sub Object_OnScriptEnter
'--Set the starting position in the middle of your screen.
object.top = system.screenheight/2
object.left = system.screenwidth/ 2
object.settimer 1, 10
End Sub
Sub object_ontimer1
'--If object has reached screen edge stop
If object.left <= 0 then
object.killtimer 1
'--If object has not reached screen edge keep moving
Else
object.left= object.left - 2
End If
End Sub
STEP 3- Scrolling in a loop
We want to make the object go back to the starting position and keep scrolling in a loop.
This time we'll declare the starting positions as variables and use them to set the object's position.
Dim startposX
Dim startposY
startposX = system.screenwidth/ 2
startposY= system.screenheight/ 2
Sub Object_OnScriptEnter
'--Set the starting position in the middle of your screen.
object.top = startposY
object.left = startposX
object.settimer 1, 10
End Sub
Sub object_ontimer1
'--If object has reached screen edge go back to starting position
If object.left <= 0 then
Object.left = startposX
End If
'--Move object back 2 pixels everytime the timer fires
object.left= object.left - 2
End Sub
STEP 4- Small scale scrolling
Now that we're getting the hang of the art of scrolling, let's downsize it to scroll in a smaller area.
This is useful for RSS feeds or media player information.
We need to create another object. Call it "maskobject". Use a plain image. Make it 200 W x 30 H.
Now position the text object inside the mask.
Next go to the text object's properties and set the parent to the mask.
You should have this:
Okay, now for the script.
We want to make it wait before starting to scroll.
We need to make sure the text is completely out of view before starting over.
We need to set a new 'start over' position.
Dim startposX
Dim startposY
Dim startoverpos
startposX = desktopx.object("maskobject").width/2 - object.width/2
startposY= desktopx.object("maskobject").height/2 - object.height/2
startoverpos= desktopx.object("maskobject").width
Sub Object_OnScriptEnter
'--Set the starting position at center of mask
object.top = startposY
object.left = startposX
object.settimer 1, 2000
End Sub
'---2 second pause before scrolling
Sub object_ontimer1
object.settimer 2, 10
object.killtimer 1
End Sub
Sub object_ontimer2
'--If object is completely out of view move to start over position
If object.right <= 0 then
Object.left = startoverpos
End If
'--Move object back 2 pixels everytime the timer fires
object.left= object.left - 2
End Sub
STEP 5- Getting Creative
PAUSE SCROLLING EACH LAP
Now, let's get creative.
Here is a script that will pause the text just before it goes out of view.
The start position is set to the left-most side of the mask.
The text moves 1 pixel at time.
Dim startposX
Dim startposY
Dim startoverpos
startposX = 2
startposY= 10
startoverpos= desktopx.object("mask").width
Sub Object_OnScriptEnter
'--Set the starting position center of mask
object.top = startposY
object.left = startposX
object.settimer 1, 10
End Sub
'---2 second pause before resuming scrolling
Sub object_ontimer2
object.killtimer 2
object.settimer 1, 10
End Sub
Sub object_ontimer1
'--Stop scrolling when object reaches left-most side
If object.left = 1 then
object.killtimer 1
object.settimer 2, 2000
End if
'--If object is completely out of view move to start over position
If object.right <= 1 then
Object.left = startoverpos
End If
'--Move object back 1 pixel everytime the timer fires
object.left= object.left - 1
End Sub
SCROLLING A GROUP
You may have more than one text object you want to scroll along the same space.
This was a challenge I came across while trying to make an RSS feed.
Create a maskobject, 200 W x 30 H.
Create a text object.
Name your text object with the name ending in the number 1.
My text object is called "info1" so when we clone it, the clones will be numbered accordingly (e.g. info2, info3 etc.). This is very important.
Make your text object’s parent the maskobject.
Next, clone your text object as many times as you want.
Group all of your text objects. Call the group "scrollinginfo".
You should have this:
Now, we need to declare how many objects are in the group.
We need to align our objects with equal spacing in between each text object.
We want to pause each object when it reaches the left-most side.
We need to send each object to the ‘end of the line’ when it’s scrolled out of view.
Insert this script into the “maskobject”
Dim startposX
Dim startposY
Dim spacing
Dim objcount
startposX = 2
startposY= 8
spacing= 50
objcount= Desktopx.GroupObjects("scrollinginfo").count
Sub Object_OnScriptEnter
'--Set the starting position and align all objects in group
For Each elem In Desktopx.GroupObjects("scrollinginfo")
elem.top = startposY
Next
For x = 1 To objcount
If x = 1 Then
Desktopx.Object(“info1”).Left = 2
Else
Desktopx.Object("info" & x).left = Desktopx.Object(“info" & x-1).right + spacing
End If
Next
Object.SetTimer 2, 2000
End Sub
'---2 second pause before resuming scrolling
Sub object_ontimer2
object.killtimer 2
object.settimer 1, 10
End Sub
Sub object_ontimer1
'--Move each object in the group
For Each elem In Desktopx.GroupObjects("scrollinginfo")
elem.left = elem.left - 1
'--If an object has scrolled out of view call function to loop the object
If elem.right < 0 Then
Call LoopText
'--Pause when an object reaches the left-most side
‘—This can be commented out if you don’t want to pause
ElseIf elem.left = startposX Then
object.KillTimer 1
object.SetTimer 2, 2000
End If
Next
End Sub
'---Function to identify object that has scrolled out of view and move it to end of the line
Function LoopText
For x= 1 To objcount
If x = 1 Then
'--If first object in group has scrolled out of view, reposition it after the last object in group
If desktopx.object("info" & x).right < 0 Then
desktopx.Object("info" & x).left = desktopx.Object("info" & objcount).right + spacing
End If
Else
'--If any other object in group has scrolled out of view, reposition it after the object that comes before it
If desktopx.Object("info" & x).right < 0 Then
desktopx.Object("info" & x).left = desktopx.Object("info" & x-1).right + spacing
End If
End If
Next
End Function
I also recommend these scrolling scripts by other coders:
Here--
Link
Here--
Link
Thanks for reading. Comments and suggestions are welcome.
"
Popular Articles in this Category
DesktopX 3: Creating a widget
Popular Articles from sViz
Happy GDPR Day...
Comments
1
sweetasman01
on Jan 04, 2007
Thanks, this is a good tute. I just started to learn how to program so am still learning the basics but this should be useful.
2
MichaelG
on Jan 09, 2007
Just wanted to say thanks for the tutorial. It's great that you are taking the time to help us the new users of DesktopX to learn it internal workings. I noted that the images in this tutorial are broken, and thought you should know. The properties of the images indicate they live on msnuser.com. Unless a person has a membership to msn that person would not be able to see these images. Thought you should know....
3
sViz
on Jan 10, 2007
Unless a person has a membership to msn that person would not be able to see these images.
Oh,no! I didn't know that. As soon as JoeUser allows me back into my blog I'll fix it.(the site is having some issues) Thanks, MichaelG.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
Richer content, access to many features that are disabled for guests like commenting on the forums.
Access to a great community, with a massive database of many, many areas of interest.
Access to contests & subscription offers like exclusive emails.
It's simple, and FREE!
Sign Up Now!
Meta
Views
» 9346
Comments
»
3
Category
»
DesktopX Tutorials
Comment
Recent Article Comments
Let's see your political mem...
LightStar Design Windowblind...
Let's start a New Jammin Thr...
A day in the Life of Odditie...
Safe and free software downl...
Veterans Day
A new and more functional PC...
Post your joy
AI Art Thread: 2022
WD Black Internal and Extern...
Sponsored Links