Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:15 01 Aug 2025 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: rocket demo and the case of the flickering sprites

Author Message
datawiz

Newbie

Joined: 10/08/2020
Location: United States
Posts: 26
Posted: 03:05am 27 Aug 2020
Copy link to clipboard 
Print this post

I put together a little sprite demo in an attempt to make sense of all the stuff I've been reading about around sprites and graphics. Hopefully it's helpful as an example to others.

You can find it here: rocket_sprite_demo.zip

I do have a question that I hope someone can help me with-- What can I do to reduce the amount of flickering I see when moving the rocket and comet sprites in the demo?
I've tried to sync to the VGA frame blank interval (using the MODE option and a flag variable) before updating with the 'sprite show', but I'm still seeing flickering. Maybe I'm misunderstanding how it's supposed to work..? But I see as much flickering using it as not using it. I'll continue to tinker, but hopefully someone can spot what I've done... :)

Any help is much appreciated! Thanks in advance.

Rich/dw
Edited 2020-08-27 13:14 by datawiz
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 05:05am 27 Aug 2020
Copy link to clipboard 
Print this post

I think I found the issue.

vsync% is probably getting set to 1 in an interrupt during this line:
pause 40

in which case the check at the start of next loop:

do while vsync% = 0: loop


won't wait at all for another blank period

solution - set vsync% = 0 right before the loop, or maybe try to count multiple frames with getvsync instead of just one.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 05:26am 27 Aug 2020
Copy link to clipboard 
Print this post

Nice work.

I can remove the flicker by adding "do while vsync% = 0: loop" before the page scroll and "vsync% = 0" after in the sections that both move the rocket or comet sprites AND scroll the stars.

For example:
' scroll the rocket in from the lower left
x% = -39
for y% = 199 to 70 step - 1
 page write 1
 do while vsync% = 0: loop
 sprite show sp_rocket,x%,y%,0
 vsync% = 0
 do while vsync% = 0: loop      ' <=== ADD THIS LINE
 page scroll 0,moveh,movev
 vsync% = 0                     ' <=== ADD THIS LINE
 x% = x% + 1
 pause 40
next y%


I guess one vertical blanking period isn't enough time to both move the sprite and scroll the stars, although why the sprite flickers even though it is moved first immediately upon blanking is strange.

------
Capsikin is right. Set vsync% = 0 immediately before "do while vsync% = 0: loop"
(Or alternately "vsync% = 0 : do : loop until vsync%")
Edited 2020-08-27 15:31 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 06:46am 27 Aug 2020
Copy link to clipboard 
Print this post

Is it to do with using PAUSE 40?

I suspect the issue is that the main loop (well, everything) needs to sync with the hardware (in this case I suppose it's the vert refresh or whatever it's called).

I think in effect the PAUSE 40 means you have two timers (the video hardware & the PAUSE) which are not properly synced.

One of the games programming guys will know :)

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 07:21am 27 Aug 2020
Copy link to clipboard 
Print this post

You have what is commonly known as a race condition. Move all the "vsync%=0" lines to just above the "do while vsync%: loop" lines and it works fine
 
datawiz

Newbie

Joined: 10/08/2020
Location: United States
Posts: 26
Posted: 08:20pm 27 Aug 2020
Copy link to clipboard 
Print this post

Many thanks to everyone for the help!
I've updated the demo, rearranging the vsync%=0 to occur before the "do while vsync%=0:loop" and it is now flicker free!

rocket_sprite_demo-v2.zip

I've also removed the external sound files, and decided to use the "play sound" commands on different channels for all sound effects, giving it a much more authentic 8/16 bit sound experience, and making it even easier to time the sound effects to the animation and introduce volume changes for near/far objects. I've also made it easier to see the alternate ending animation. lol.

I'm looking forward to doing more graphics/animation on the cmm2. Next, composing the scene to a separate page and doing a page copy to the displayed page. That seems like a simpler way to get flicker free animation, but it really helped for me to do it this way first.

Regards,
Rich/dw
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025