Author Topic: BlitzBasic : Soft Sine Scroller[BB2D]  (Read 3476 times)

0 Members and 1 Guest are viewing this topic.

Offline Dad1916

  • Atari ST
  • ***
  • Posts: 112
  • Karma: 3
    • View Profile
BlitzBasic : Soft Sine Scroller[BB2D]
« on: August 18, 2006 »
"If there was one thing that really was a "must" on almost every demo on the Amiga-scene, that would have to be a soft sine scroller.
Therefore I made one for you to study. This code is NOT optimized for speed, it was written to be as easy to understand as possible ! There are at least a 100 ways to do a soft-sine scroller, this is one of them ! (Using up to 900 sprites) Charset is taken from the "Oldschool"-example in the BB help-file by Shane R. Monore. Using tables for sinus would improve performance a LOT since then there would be no use for the floats (which are really slow). Maybe I'll make a table-version if anyone bothers to bug me about it ;-) I packed it all i a zip file for this one since a gfx-file is needed for the example. Source included !"

BB-Ver. 1.48

Posted with permission of the author Einar Wedoe of http://blitzbasic.no/
Exe here http://blitzbasic.no/div/soft-sine.zip


Code: [Select]
AppTitle "Soft Sine Scroller"
;-----------------------------------------------
; Version Beta 1
; May 2001
; Made by Einar Wedøe
; Programtype: Soft Sinus Scroller
;-----------------------------------------------
Graphics 800,600,16,1
Dim degree#(5) ; Dim up sinus-waves
Dim startdegree#(5) ; Start for sine on each frame
Dim count#(5) ; Dim up sinus-counters
Dim wavespeed#(5)

Global speed=2 ; Speed of scroller (max 5)
Global numberofsines=3 ; Number of sines to calculate y (max 5)

For a=1 To 5 ; Ranomize sinus
 count#(a)=Rnd(-2,2)
 wavespeed#(a)=Rnd(-2,2)
Next

Type softletter ; Type for each pixel of all letters
    Field x,y ; X and Y pos
Field frame ; Wich frame ?
End Type

Global alphabet=LoadAnimImage("finalfont.png",1,27,0,690) ; Loadfont
Global widthcount=0 ; Count letterwith
Global currentletterwith=40 ; Holds letterwith
Global scrollcount=0 ; Pointer in scrolltext-string
Global scrolltext$="" ; The text to show
Global plotsy#=0 ; Y-pos
Global textavailible$="" ; Holder for availible letters
Global sinecount=10
Dim letteroffset(35) ; Offset in bitmap for each letter
Dim letterwidth(35) ; Width of each letter

SetBuffer BackBuffer()
Color 255,255,255

Gosub initscroller ; Put scrolltext in scrolltext$-string

For a=1 To 500 ; Fill screen with emty types
  scrollcount=0  
  newletter ; to make sinuseslook right
  wave
Next

« Last Edit: July 21, 2007 by Shockwave »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: BlitzBasic : Soft Sine Scroller
« Reply #1 on: August 18, 2006 »
This example is really nice, it's very well commented and what I really like about it is that it uses a proportional font, but you're not going to like me here;

I don't think it is as simple as it could be or anywhere near as optimised as it should be though. If you'd like I'll make an example for you.

A few pointers, it would be much easier to lay the font out in the same order as the letters appear in the asciii set and as space is chr$(32) you could have;

Letter = ASC(mid$(string$,POINTER,1)) - 31

If your font animimage starts at the space character.

In my own tests Types were slower than array access and for something like a scroller (Unless it's doing anything fancy) there is just no need to use types.

In fact this would be better done using straight drawblockrect and probably be 10 times easier to understand and 10 times faster, using precalculated sin tables would give you a little tiny bit of speed gain but not much, maybe only 1 - 2 fps.
When you are optimising it is best to focus on the most intensive parts of your program and these days with modern PC's you'd be surprised how fast FPU is for something like a sine scroll.
Shockwave ^ Codigos
Challenge Trophies Won: