Help with smooth movement of tiled sprites
Posted: Thu Jun 09, 2016 3:28 pm
I am trying to move tiled sprites in sync with one another and am experiencing jitter where I was expecting seamless movement. Here is a simplified example which is intended to move two sprites side-by-side.
How I expected the sprites to look at all times:
How it often looks when the sprites are moving:
The lines "SPRITE 1 AT x, y" and "SPRITE 2 AT x + S.w, y" are right next to each other, yet it seems that moving Sprite 1 sends an update to the screen before I move Sprite 2. Is there any way to force smart BASIC to not refresh Sprite positions until I tell it to? Something like:
I know those commands don't exist but I'm asking if there is some way to essentially get that behavior. (Using the REFRESH OFF and REFRESH commands for the graphics screen as an example.)
Code: Select all
GRAPHICS
REFRESH OFF
GRAPHICS CLEAR 0,0,0
REFRESH
OPTION SPRITE POS CENTRAL
GET SCREEN SIZE scrW, scrH
DRAW COLOR 0,0,0
' Scope "S" contains sprite data
S.w = 60
S.h = 60
S.x = scrW/2
S.y = scrH/2
FOR s = 1 TO 2
SPRITE s BEGIN S.w, S.h
GRAPHICS CLEAR 1,1,1
FOR x = 0 TO S.w*2 STEP 10
DRAW LINE 0,x TO x,0
DRAW LINE x-S.w,0 TO x,S.h
NEXT x
SPRITE s END
NEXT s
SPRITE 1 AT S.x, S.y
SPRITE 2 AT S.x + S.w, S.y
SPRITE 1 SHOW
SPRITE 2 SHOW
' Scope "T" contains touch data
T.touch = 0
WHILE 1
GET TOUCH 0 AS T.x, T.y
IF T.x <> -1 AND T.y <> -1 THEN
IF T.touch = 0 THEN
T.touch = 1
T.x0 = T.x
T.y0 = T.y
END IF
x = S.x + T.x - T.x0
y = S.y + T.y - T.y0
SPRITE 1 AT x, y
SPRITE 2 AT x + S.w, y
ELSE
IF T.touch = 1 THEN
T.touch = 0
GET SPRITE 1 POS S.x, S.y
END IF
SLOWDOWN
END IF
END WHILE
How it often looks when the sprites are moving:
The lines "SPRITE 1 AT x, y" and "SPRITE 2 AT x + S.w, y" are right next to each other, yet it seems that moving Sprite 1 sends an update to the screen before I move Sprite 2. Is there any way to force smart BASIC to not refresh Sprite positions until I tell it to? Something like:
Code: Select all
SPRITE REFRESH OFF
' ...
SPRITE 1 AT x, y
SPRITE 2 AT x + S.w, y
SPRITE REFRESH