• Welcome to Dark Bit Factory & Gravity.
 

Scrolling Text . . . Help Please?

Started by DrewPee, July 11, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

DrewPee

Hello there,
Im a newbie to Freebasic (but i have been using Amos and Blitz for a LONG time!).
How would i do a scrolliing text message (at various sizes and fonts) easily and smoothly?
I know the basics of doing it i.e. a string of text etc. . .
Hope somebody can help me . . .
Regards
DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

It can be very simple and it can be difficult.
Here's the hard way first;

This uses a library called tinyptc, you'll see it at the top of the listing "include once 'tinyptc.bi"
All that tinyptc does is handles a screen buffer, it updates the screen from a block of memory (an array), it opens a screen, it closes the screen. So everything has to be done pixelwise..

http://dbfinteractive.com/index.php?topic=224.0

There are other options though fortunately and freebasic has a lot of graphics commands which you can use instead of tinyptc if you like.

I'll do a simple version for you shortly.
Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

Thanks once again Shockwave for sharing code . . . without you . . . etc.
Regards
Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

Here you are, I was going to code another scroller example but in my haste I realised that the print command only works on screens in up to 8 bits and I guess that what you really need to be seeing at the moment is how to get some simple images moving around..
So here is a very, (and I mean very) quick program to show you how cool the built in gfxlib command is.. I have just used some circles here as bobs and it shows the built in alpha blending.


'
' Simple Graphics Example For Drew By Shockwave^DBF ;
'
'-------------------------------------------------------------------------------

    OPTION STATIC:' Preserve Variable Values Between Procedure Calls
    OPTION EXPLICIT:' Requite VAriables To Be Declared Before Use
   
'-------------------------------------------------------------------------------
' SET SCREEN MODE
'-------------------------------------------------------------------------------

    CONST XR = 640: ' XRES
    CONST YR = 480: ' YRES
    DIM SHARED AS INTEGER HXR,HYR
   
    HXR = (XR / 2) - 8
    HYR = (YR / 2) - 8
   
    windowtitle "Example of some bobs. alt + enter fullscreen"   
    'OPEN SCREEN XRES, YRES , BIT DEPTH , PAGES ,  FLAGS , REFRESH RATE
   
    SCREENRES XR , YR , 32 , 2 ,  ,
   


'-------------------------------------------------------------------------------
' INITIALISE DOUBLE BUFFERING VARIABLES;
'-------------------------------------------------------------------------------

declare sub db()
dim shared as integer workpage,vispage
workpage=0
vispage=1

'-------------------------------------------------------------------------------
' SORT OUT BALL GFX!
'-------------------------------------------------------------------------------


        DIM AS INTEGER VV,a,q,BNUMT
        DIM SHARED BALL (14) as any ptr:' 7 Ball Gfx!
       
        COLOR &HFFFFFF,&H000000:' fOREGROUND + bACKGROUND COLOURS

Q=1
for a=1 to 14
    BALL (a) = imagecreate (16,16 , &HFF00FF)  :' NB PINK IS TREATED AS MASK! 

    circle BALL (a),(8,8),Q
   
    IF A<7 THEN :' IF THEN AND ELSE WORK COOL THE SAME AS BLITZ.
        Q=Q+1
    ELSE
        Q=Q-1
    END IF
   
   
next



dim  shared as integer ZZ , GADD , balls , svx , svy
balls = 1000
dim shared bnum(balls)

for a=1 to balls
bnum(a)=(rnd*(13))+1
next

'-------------------------------------------------------------------------------
' MAIN LOOP:
'-------------------------------------------------------------------------------

DO
        DB()
        CLS
        BNUMT=BNUMT+1
        IF BNUMT>5 THEN BNUMT=1
       
        for zz=1 to balls
            svx = HXR  + (300*sin(( GADD + zz)/33))
            svy = HYR  + (200*cos(( GADD + zz)/52))
    '---------------------------------------------------------------------------
    ' AS YOU CAN SEE, IT'S QUITE EASY TO HAVE ALPHA, SPECIFY ALPHA THEN A VALUE
    ' OF 0 TO 255
    ' OTHER MODES INCLUDE PSET, XOR , TRANS ETC...
    '---------------------------------------------------------------------------
                put (svx,svy) , BALL (bnum(zz)) , ALPHA , 125
                IF BNUMT=1 THEN BNUM(ZZ)=BNUM(ZZ)+1
                IF BNUM(ZZ)>14 THEN BNUM(ZZ)=1
        next
        GADD=GADD+1
       
LOOP UNTIL INKEY$=CHR$(27)


'-------------------------------------------------------------------------------
' Double Buffering, Remember to declare this sub and call it once per update.
'-------------------------------------------------------------------------------

sub DB()
   
    '===============
    '=DOUBLE BUFFER=
    '===============
   
    SCREENSET WORKPAGE,VISPAGE   
    SCREENSYNC
    WORKPAGE  XOR = 1
    VISPAGE  XOR  = 1

end sub


Unfortunately all the stuff I've done with text uses tinyptc, it would not be hard to load a font as a bitmap..
Anyway have a play with this and see if it helps you get to grips with the language. A good exercise for you would be to change this into a 2D starfield with different size bobs so you can get used to defining your variables etc..
Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

Thanks man - thats just the sort of start i needed - pretty simple when you have help.
Very much appreciated.
Regards
Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

thrawn89

Quote from: DrewPee on July 11, 2006
Hello there,
Im a newbie to Freebasic (but i have been using Amos and Blitz for a LONG time!).
How would i do a scrolliing text message (at various sizes and fonts) easily and smoothly?
I know the basics of doing it i.e. a string of text etc. . .
Hope somebody can help me . . .
Regards
DrewPee

I would make your own set of font images [a set of PNGs would be ideal, cause they have partail alpha capabilities]

After you load them, you can then use PUT (x,y), ImageBuffer, ALPHA them onto the screen wherever you wish

If you dont want to go through all that work, you may use freebasic's own set of font images using PRINT and LOCATE to place them

As for changing the font set, I believe there was some way to change the built in fonts, you'll have to consult the docs for that

Let us know which way you decide and we can help with any other specific questions you have later on...

For documentation and listing of the Keywords: FBWiki
For any extra help: FreeBaisc Offical Forum

Thrawn

DrewPee

Thanks Thrawn - I guess these forums are possibly the best ive been on for a long time - the friendship and support is immense.
Very helpful information . . . hope this helps other people out as well.

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

You've really got to check out Thrawn's Ploader library (in the completed work forum), it will let you load your png images straight into your program with no hassle.
Shockwave ^ Codigos
Challenge Trophies Won:

thrawn89

#8
I would wait until downloading it if you can...counting_pine and I will be releasing the final version soon once he gets back with all of the bugs fixed, and a little better in efficency, and a couple more features implemented...also a Pload_GetError() function that will return the error or lack of error of the last call to pload or mpload [mpload, allows you to load a png into an fb image file in one step if you have the datastream in a buffer already and do not need to load it from a file]...

Also you might want to check out this: http://www.freebasic.net/forum/viewtopic.php?t=4978

It shows you how to resource and read a png in your file using the unreleased version of ploadlib...so with fonts especially, you wont need 80 pngs in a folder, instead you can have them included your exe...this is also good because its a lot more difficult for users to change *hack* them...[it still can be done, unless if you encrypt the files...but thats probally unneeded to do]

BTW: I agree, this forum has a much better sense of friendliness and community...

Thrawn

Shockwave

The ability to rescource pngs will be the thing that totally sells it as far as I'm concerned and do you know what, if I get the time to do it I'll probably even make a game in Freebasic.. I haven't coded a game for ages.
Shockwave ^ Codigos
Challenge Trophies Won: