Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ScrollLeft function scrolling more than 1 pixels left
#1
Hello,

I'm trying to use the ScrollLeft function to create a scrolling chart and the ScrollLeft function seems to be scrolling more than 1 pixel left. 
The screening area on the left also seems to be not to be pixel acurate. 

Sample program:

Code:
#include <scroll.bas>

INK 7
PAPER 0
CLS
sub square(x1 as UBYTE, y1 as UBYTE, x2 as UBYTE, y2 as UBYTE, color as UBYTE)
    DIM x AS UBYTE = 0
    DIM y AS UBYTE = 0
    FOR x = 0 TO x2 - x1
        PLOT INK color; x1 + x, y1
        PLOT INK color; x1 + x, y2
    NEXT x
    FOR y = 0 TO y2 - y1
        PLOT ink color; x1, y1 + y
        PLOT ink color; x2, y1 + y
    NEXT y
END SUB
SUB plott(x as FLOAT, y as FLOAT, sx as FLOAT, sy as FLOAT, x1 as UBYTE, y1 as UBYTE, x2 as UBYTE, y2 as UBYTE, color as UBYTE)
    DIM alfa AS UINTEGER
    DIM beta AS UINTEGER
    DIM mx AS UINTEGER
    alfa = ((x/sx) * (x2 - x1)) + x1
    beta = ((y/sy) * (y2 - y1)) + y1 + ((y2-y1)/2)
    ' Limites da tela
    IF alfa >= x2 - 1 then alfa = x2 - 1
    IF beta <= y1 + 1 then beta = y1 + 1
    mx = alfa mod x2
    IF alfa >= (x2-1) then
        ScrollLeft(x1 + 1, y1 + 1, x2 - 1, y2 - 1)
        alfa = x2-1
    END IF
    PRINT at 10,10; "alfa: "; alfa
    PRINT at 11,10; "beta: "; beta
    PLOT ink color; alfa, beta
END SUB
square(10, 15, 80, 60, 6)
DIM dia AS INTEGER
DIM valor AS float = 0
DIM incremento AS FLOAT = 1
' Create a sample scrolling chart
FOR dia = 1 TO 5000
    plott(dia, valor, 360, 100000, 10, 15, 80, 60, 6)
    valor = valor + 1000 * incremento
    IF valor > 49000 then incremento = -1
    IF valor < -49000 then incremento = 1
NEXT dia


Thank you very much!
Reply
#2
Yes, thatś right. For horizontal scroll, it's very difficult to do a pixel precise frame scroll. It does it in 8 pixels wide blocks. Doing it pixel perfect, due to ZX Spectrum architecture, would be really slow. I still can provide you a scroll routine that does exactly that, but be aware that it will be REALLY slow.

For vertical scroll this does not happen and it's pixel perfect.

A simple solution is to place your rectangle in an aligned zone.
You can draw the box frame out of the inner part that will be scrolled:
Code:
square(7, 15, 80, 60, 6)
This should work

One more thing: Float is REALLY slow and expensive. Consider using Fixed instead of Float and only if necessary. Most of the time you will need just Uinteger or Ubyte values.
Reply
#3
Thank you very much for your reply and clarification about the Fixed type. I'll fix that to save as much resources as possible.
Since my program is a simulation and not an action/arcade game, I bet would not have a great problem doing the fine horizontal scroll because the chart will not be refreshed intensively (it will receive an update each 3/4 seconds). If you could provide that function, I would really appreciate it Big Grin

Thank you very much
Rogerio
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)