Hi, I am trying to make a scrolling text example with 2 text objects and keep track of their "y" positions using an array when the respective buttons are pressed. Arrays are a serious weak point for me. My brain goes on overload just looking at arrays.
For my example I have a text file named Team.txt with the following text inside:
Player 1
Player 2
I want the text to be put into the 2 text objects that are displayed on the screen. For the "UP" button I want the text to move down the screen like you are scrolling to the top of a list and the "Down" button move the text up like you are scrolling down the list
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Scrolling Text" )
SetWindowSize( 640, 480, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 640, 480 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
Global Text$
Global T_Players = 2
Text as integer
y as integer
TxtObj as integer [ 1 ]
T_Obj as integer
x = 50
OpenToRead(1,"Team.txt")
While FileEOF(1) = 0
For T_Obj = 1 to T_Players
For y = 250 to 350 step 100
Text$ = ReadString(1)
CreateText(T_Obj, Text$)
SetTextSize(T_Obj,15)
SetTextColor(T_Obj, 250, 250, 0, 255)
SetTextPosition(T_Obj, 50, y)
Next y
Next T_Obj
EndWhile
AddVirtualButton(1,400,200,40)
SetVirtualButtonSize(1,50,50)
SetVirtualButtonColor(1,10,0,200)
SetVirtualButtonText(1,"UP")
AddVirtualButton(2,400,400,40)
SetVirtualButtonSize(2,50,50)
SetVirtualButtonColor(2,10,0,200)
SetVirtualButtonText(2,"DOWN")
do
For T_Obj = 1 to T_Players
x = GetTextX ( TxtObj [ T_Obj ] )
y = GetTextY ( TxtObj [ T_Obj ] )
If GetVirtualButtonState(1)=1
SetTextPosition(T_Obj,50,y-5)
Endif
If GetVirtualButtonState(2)=1
SetTextPosition(T_Obj,50,y+5)
Endif
Next T_Obj
sync()
loop
Gigabyte Board/ AMD 3.3 Ghtz Quad core/8GB Ram/Nvidia Geforce 1080 GTX 8GB/1TB Western Dig. SSD/Windows 10 Home/Dark Basic Pro 9Ex/AGK2/AGKStudio
No one cares how much you know until they know how much you care.