Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:38 24 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 sprite screen flickering

Author Message
freemesy
Newbie

Joined: 26/07/2021
Location: Hungary
Posts: 2
Posted: 09:07am 27 Jul 2021
Copy link to clipboard 
Print this post

Hi to all forum members!

I've got problem with programming CMM2 (gen 1.). The main goal is to move a sprite beyond the background. Or at least move a sprite beyond another sprite. When the move accurs (with next-move or show commands) the screen is flickering. The sprites always redraw and that cause a very ugly flickering effect. Do you have any idea how to achive the goal, not to flicker? In fact when I use the 12-bit mode the flickering is more worse then in 8-bit or 16-bit mode. Some time ago I tried to write a scroll rutine in 12-bit mode but it has got the same problem. When blit occurs the screen was alwas flickering (no sprite in that). I tried the getscanline function to make the blit or sprite move occuring when the scanline is out of the way, but no success, same result.

Here's my code:
option default none
option explicit

const vstart=150
dim integer i,j,cpos=4,pl=0

               mode 1,12
               colour RGB(White),RGB(Black)
               cls

               page write 1
               box 180,120,440,440,1,RGB(Blue),RGB(Blue)
               for i=1 to 7
                   for j=1 to 7
                       circle j*60+160,i*60+100,25,1,1,RGB(Black),RGB(Black)
                   next j
               next i
               sprite read #1,180,120,441,441,1
               circle 400,80,25,1,1,RGB(yellow),RGB(yellow)
               circle 400,80,27,4,1,RGB(180,180,0)
               sprite read #2,373,53,55,55,1
               cls
               page write 0
               cls
               sprite show safe #2,cpos*60+180,vstart,0
               sprite show safe #1,170,120,0

waitforkey:
               if keydown(0)=0 then goto waitforkey
               if keydown(1)=27 then end
               if keydown(1)=32 then goto drop
               if keydown(1)=130 and cpos>0 then
                  cpos = cpos - 1
               endif
               if keydown(1)=131 and cpos<6 then
                  cpos = cpos + 1
               endif
               sprite next #2,cpos*60+180,vstart
               sprite move
               pause 150
               goto waitforkey

drop: .........

Thanks for your help, I hope somebody has got a godd idea.

Zoltan
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 06:59pm 27 Jul 2021
Copy link to clipboard 
Print this post

I think you are just trying to draw too much.

Nothing I've tried so far using sprites works cleanly - lots of tearing.

The following uses BLIT and is better, but is still not ideal. It might be better to draw all the changing parts on page 2, then do a "PAGE COPY 2,0,B" to transfer it into view.

Picking a lower resolution mode would help too.

option default none
option explicit

const vstart=100
const xoffset=193
dim integer i,j,cpos=4,pl=0

mode 1,12
colour RGB(White),RGB(Black)

page write 1  ' create game board on page 1 - front (static) image
cls
box 180,120,440,440,1,RGB(Blue),RGB(Blue)
for i=1 to 7
 for j=1 to 7
   circle j*60+160,i*60+100,25,1,1,RGB(Black),RGB(Black)
 next j
next i

page write 2  ' create disc image on page 2
cls
circle 27,27,25,1,1,RGB(yellow),RGB(yellow)
circle 27,27,27,4,1,RGB(180,180,0)

page write 0  ' draw disc on page 0 - background behind game board
cls
blit 0,0,cpos*60+xoffset,vstart,55,55,2  ' copy disc image at starting point

do
 if keydown(0)=  0 then continue do
 if keydown(1)= 27 then end
 if keydown(1)= 32 then exit do
 if keydown(1)=130 and cpos>0 then
   cpos = cpos - 1
 endif
 if keydown(1)=131 and cpos<6 then
   cpos = cpos + 1
 endif
 cls   ' erase everything
 blit 0,0,cpos*60+xoffset,vstart,55,55,2  ' draw disc in new position
 pause 150
loop

for i = vstart to 494 step 5  ' drop disc down screen
 do : loop until getscanline > 499 ' trial and error - not ideal
 box 190,100,420,460,0,RGB(Black),RGB(Black) ' erase previous - smaller area would be better
 blit 0,0,cpos*60+xoffset,i,55,55,2  ' draw disc in new location
 pause 2  ' brief pause so video catches up
next i

do : loop until inkey$ <> ""

Visit Vegipete's *Mite Library for cool programs.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8575
Posted: 07:13am 28 Jul 2021
Copy link to clipboard 
Print this post

One big change would be to only redraw the sprite if it has moved.
 
freemesy
Newbie

Joined: 26/07/2021
Location: Hungary
Posts: 2
Posted: 07:39am 28 Jul 2021
Copy link to clipboard 
Print this post

Thanks for your replies.      
Vegipete's advice and code was perfect. I learn from that so much.
It works like a charm.

Thank you for your effort to explain things for an "almost beginner".  
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 02:23pm 28 Jul 2021
Copy link to clipboard 
Print this post

If I remember correctly my tile demo game here was able to move sprites around without flickering. It does it by calling the sprite move command right after a frame-blanking interrupt.

I do remember it was harder to get rid of the flicker at higher resolutions - at 640x400 I only updated the screen every second frame, whereas I might have been able to update every frame at a lower resolution.

12-bit modes (and higher resolution modes) use more memory bandwidth to read the screen memory while displaying it to the VGA port, that's probably why they flicker more.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024