Scrolling text example passing by reference
type myText
id as integer :rem id of sprite
x as integer :rem x axis
y as integer :rem y-axis
img as integer :rem holds the image number for the sprite
endtype
#constant font =1
#constant Bg=1000
#constant startText =100
// set window properties
SetWindowTitle( "Test set pivot" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
LoadFont(font,"KenneyThick.ttf")
intro()
end
function intro()
logo as integer
logoImg as integer
AGKlogo as integer
AGKlogoImg as integer
strlen as integer
//logo=LoadObject("KrazyGrandPrix3DLogo.obj")
//logoImg=LoadImage("KrazyGrandPrix3DLogoD.png")
//SetObjectImage(logo,logoImg,0)
//SetObjectScale(logo,.2,.2,.2)
//SetObjectPosition(logo,0,8.25,0)
AGKlogo=LoadObject("AGKlogo.obj")
AGKlogoImg=LoadImage("AGKlogoD.png")
SetObjectImage(AGKlogo,AGKlogoImg,0)
SetObjectScale(AGKlogo,.25,.25,.25)
SetObjectPosition(AGKlogo,0,-2.0,0)
textSpr as myText[90]
setupCredits(textSpr)
repeat
fubarpkTextScroll(textSpr)
RotateOBjectLocalY(AGKlogo,1)
//RotateOBjectLocalX(logo,.5)
Sync()
until GetPointerPressed()
DeleteAllObjects()
DeleteAllSprites()
DeleteAllText()
DeleteAllImages()
endfunction
function fubarpkTextScroll(textSpr ref as myText[])
num as integer
strlen as integer
strlen=textSpr.length
for num = 1 to strlen
textSpr[num].x=textSpr[num].x-1
if GetSpriteExists(textSpr[num].id) then SetSpritePosition(textSpr[num].id,textSpr[num].x,textSpr[num].y)
if textSpr[num].x <-20 then textSpr[num].x=GetWindowWidth() +280
next num
endfunction
function setupCredits(textSpr ref as myText[])
text$ as string
num as integer
strlen as integer
rem Credits text
text$=("Credits fubarpk, Blink0k, Bengismo, Chafari, Rick Nasher, Kenney, and TGC forums"):strLen=len(text$)
//global dim textSpr[strLen] as myText
for num=1 to strLen
textSpr[num].id=num+startText+(num-1)
textSpr[num].img=num+startText+(num-1)
textSpr[num].x=(num-1)*15
textSpr[num].y=GetWindowHeight()-33
textSpr[num].img=fubarpkCreateTextImage(Mid(text$,num,1))
createSprite(textSpr[num].id,textSpr[num].img)
SetSpriteSize(textSpr[num].id,32,32)
SetSpriteColor(textSpr[num].id,255,255,255,255)
SetSpriteTransparency(textSpr[num].id,1)
SetSpriteDepth(textSpr[num].id,10)
SetSpriteGroup(textSpr[num].id,1)
next num
endfunction
function fubarpkCreateTextImage (myString as string)
img as integer
CreateSprite(bg,0)
SetSpriteSize(bg,150,150)
SetSpriteColor(bg,0,0,0,255)
clearscreen()
CreateText(startText,myString)
SetTextFont(startText,font)
SetTextSize(startText,28)
SetTextPosition(startText,0,0)
Render()
img=GetImage(0,0,50,50):ClearScreen()
SetImageTransparentColor( img,0,0,0 )
DrawSprite(bg)
ClearScreen()
DeleteText(startText):deleteSprite(bg)
endfunction img
its late 2am here but here is a quick example I made from previous code you may find useful
sorry its the credits from KrazyGrandPrix and uses kenney font but you should be able to change that
but could use any font just may have to change the sprite sizes and in the createtextimage the get image
command to match anyfont and size. also may find in the scroller routine if you go bigger font you
may wish to change this if textSpr[num].x <-20 then textSpr[num].x=GetWindowWidth() +280
hope you find the code useful
I also find constants are very handy ie you can create a sprite as a set number for example
#constant mysprite 1 ,createSprite(mysprite,0) this can make your code much more readable and allot
better than a serious of numbers and one line to change to update all of your code if you need to
fubar