Author Topic: help! vertical 'credits' scroller  (Read 4771 times)

0 Members and 1 Guest are viewing this topic.

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
help! vertical 'credits' scroller
« on: January 17, 2012 »
hi, i am attempting to do a 'credits' scroller type screen, which i have managed to do (very unoptimized), but at the moment i have the whole text squashed into the loop (as you can see from the code).

at the moment i have the text at 30 lines of 22 chars, so 660 characters total of text. when i keep adding on text, the demo/scroller lags down a heap which i dont want.

what im trying to achieve is similar to a horizontal scroller... for example...

xres = 800
yres = 600
fontcharw = 32
fontchary = 32

position 600+32 (which is 32px offscreen) is where it pre-renders my 22 char wide line then scrolls up onto screen... as soon as that reaches -31, then pre-render the next 22 chars at position 600+32 again, scroll up still and so on.

what my code does at the moment is pre-render offscreen the full 660 characters below 600+32 and then scroll up, soon as my counter reaches the end of text + 600px yres it then loops which is fine and all, but if i can adapt this to save memory and cpu by only pre-rending 1 line at a time then scrolling, then removing 1 line at a time at the top of screen - 32px.

not sure if im explaining myself properly :/

the base code is from one of shockwaves sources that i have changed/adapted to suit my needs, if you can help me out in what i need to do to stop the full 660 chars being processed at once and only 1 line of 22chars each ~31px, thatd be great.

again... much thanks in advance.

Code: [Select]
SUB TEXT1(BYVAL SSPD AS DOUBLE)
'this sub will vertically scroll the text from offscreen bottom to offscreen top, then loop
    DIM AS INTEGER TTX,TTY,XPO,YPO,YR,COUNT

YPO=YRES+64
YR=1
XPO=48

WHILE YR<(LEN(TEXT)/22)
VTEXT1( XPO , YPO+TXPS , MID(TEXT,COUNT,1))
XPO=XPO+32 ' x character spacing
IF XPO>720 THEN
XPO=48 ' 22 chars per line at 32px each = 704. XRES-704 = 96 /2 = 48 (48PX EACH LEFT AND RIGHT BORDER)
YPO=YPO+32' y character spacing
YR=YR+1 ' line counter
END IF
COUNT=COUNT+1
WEND
TXPS=TXPS-(DV*.125)
IF TXPS <= -(LEN(TEXT)/22)*32-(YRES) THEN ' 22 CHARS PER LINE AT 32PX HEIGHT
TXPS=0
ENDIF

VTEXT1 ( 50,0,  "LINES RENDERED YR  :"+STR(YR))
VTEXT1 ( 50,30, "TXPS  :"+STR(TXPS))

END SUB

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #1 on: January 20, 2012 »
any help? i've tried to sort this out on my own.. but im pulling my hair out trying to figure it out. :/

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #2 on: January 20, 2012 »
If you attach the project files, I'll take a look at it when I get some time.
raizor

Challenge Trophies Won:

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #3 on: January 21, 2012 »
Thanks Raizor,

Attached is the project (in quite a messy state). I only have the vertical text (with stars and bg rasters) enabled at the moment, as this is what I have been trying to figure out.

I tried again for a few hours to figure this code out, but it got the better of me, so now I'm posting it here for help. I did change up the routine again (the old routine is there, but nulled out below it). A brief explanation is above the Sub Process on what I'm attempting to achieve.

Instead of blitting the whole 22char wide by ~30 lines of text onto screen at once, scrolling up, etc, I only want it to blit one line of 22chars at a time offscreen, then scroll up vertically, when each line reaches 600-32=568, it then blits the next 22 chars offscreen at yres 600+32 then continues to scroll up vertically (same as my current bin example). When it reaches the top of screen-32px (offscreen), it no longer draws.

I really hope I'm making sense here.. I'ts frazzled me at the moment :/

Thanks in advance.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #4 on: January 21, 2012 »
Thanks ttemper, I think I understand what you're trying to do. I'll give you a shout if I get confused :)
raizor

Challenge Trophies Won:

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #5 on: January 21, 2012 »
much thanks.

its like the 32x32px horizontal scrollers (single line)... that blit 32px off screen on the right, scroll left until -32 on the left so the whole scrolltext isnt rendered all at once = lag.

i want to do this for the vertical scroller, 22 chars wide, scroll from bottom to top (as the code and binary shows atm). just not having the whole text length sucked in to memory at once, as it lags down from ~50fps to ~20fps when i add in more lines of text.

as it is at the moment, if i leave it at say 10 lines of 22 chars, its ok, but if i wanted to write my whole life story, then it'd be useless 1fps render or crash.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #6 on: January 21, 2012 »
What version of FreeBasic are you using?
raizor

Challenge Trophies Won:

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #7 on: January 21, 2012 »
Freebasic Editor 1.0.7.6c

with

FreeBASIC Compiler - Version 0.23.0 (08-14-2011) for win32 (target:win32)
Copyright (C) 2004-2011 The FreeBASIC development team.
Configured as standalone
objinfo enabled using FB BFD header version 217

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #8 on: January 22, 2012 »
I'm not sure if I've fixed it as it's a bit hard to figure out what's going on ;)

I've changed the TEXT1 method to the following:

SUB TEXT1(BYVAL SSPD AS DOUBLE)

DIM AS INTEGER SCV2=48 ' 22 CHARS PER LINE AT 32PX EACH = 704. 800-704/2=48, SO TO KEEP IT CENTERED ON SCREEN, 48PX PAD LEFT BORDER
DIM AS INTEGER A,XJUMP,CPL=22,NUML
Dim As Integer yPos
'CPL = 22 CHARACTERS PER LINE 32*22 = 704, WHICH IS LESS THAN 800 = IT FITS :p
NUML=LEN(TEXT)/CPL

   FOR A=1 TO NUML      
      XJUMP=XJUMP+32 ' 32PX ADDED TO XRES#
      yPos = SCV1+XJUMP
      If (yPos > -32 AND yPos < YRES + 32) Then
         VTEXT1(SCV2,SCV1+XJUMP,MID(TEXT,VTP,CPL))
      End If

      VTP=VTP+CPL
   NEXT

IF SCV1< -(NUML*32) THEN'-YRES THEN
   VTP=VTP+CPL
   SCV1=YRES+32
   LOOPNUM=LOOPNUM+1
ENDIF

IF VTP>CPL THEN VTP=1
      
SCV1=SCV1-(DV*SSPD*.3) ' CRAP TO MOVE THE TEXT UPWARDS

   '-------------------------------------------------------------------------------
   'DEBUG SHIT RENDERED TO SCREEN
   VTEXT1(60,400,"SCV1 (YPOS)   :"+STR(SCV1))
   VTEXT1(60,430,"SCV2 (XPOS)   :"+STR(SCV2))
   VTEXT1(60,460,"LINES RENDERED:"+STR(NUML))
   VTEXT1(60,490,"LOOP NUM      :"+STR(LOOPNUM))
   VTEXT1(60,520,"VTP           :"+STR(VTP))
   '-------------------------------------------------------------------------------

END SUB

Hopefully that should improve things.

All it does it calculate the Y position that the line is going to be drawn at and stores it in the yPos variable. It then checks the value of yPos to determine if it's somewhere between -32 and [screenHeight]+32. If it is, the line is drawn. This is just checking that the line is somewhere visible on the screen (and not scrolled off the top or the bottom) before drawing it.

It's probably a good idea to give your functions and variables more meaningful names, especially when starting out. TEXT1, SCV1, SCV2 are quite hard to follow. I can't be sure if it's running as lot quicker as there's no FPS counter, but the changes should improve things - hopefully :)
raizor

Challenge Trophies Won:

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #9 on: January 22, 2012 »
Raizor, much thanks.  :updance:

I did try and attempt that loop, but I put in....

     
Code: [Select]
If (SCV1 > -32 AND SCV1 < YRES = 32) Then
         VTEXT1(SCV2,SCV1+XJUMP,MID(TEXT,VTP,CPL))
      End If

But of course that didnt work too well. I did also attempt other loops, but didn't succeed. Now to mod my code that 'little bit more', as I did find errors/things I didnt need.

Much much thanks for checking where I went wrong, tha'ts exactly how I intended for the vertical scroller to be. Perfect.

Much thanks again Raizor, It's helping me learn where I'm going wrong... HUGE learning curve for me.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: help! vertical 'credits' scroller
« Reply #10 on: January 22, 2012 »
You're welcome ttemper :)
raizor

Challenge Trophies Won: