How to erase without flicker?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: How to erase without flicker?

Post by llewelyn »

Thanks Robin, yes I am anticipating eventually moving by pixels but first things first. I need to cut and paste all these useful pieces of programming info, thats the trouble with message bases, locating the hidden gems!
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: How to erase without flicker?

Post by Nomad »

Another reason to be more careful about the use of CLS. You are giving up control of how you refresh the screen. If at some point you want to have more elements on the screen odds are you don't want to re-draw them every time you move the player object. CLS throws everything in the bin. The overwrite techniques give you flexibility/options that you wouldn't otherwise have.

A little bit of ghosting I wouldn't sweat as long as it didn't impact gameplay. You got to think about how much time/effort its going to take to get something perfect and if it is possible/worth it. Depends how you are wired I guess.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: How to erase without flicker?

Post by llewelyn »

You're quite right Nomad and I think R-Tape said much the same thing. I only used CLS in the first iteration as a quick and dirty, easy way to get the job done. Also I have since discovered that chasing the ghosts isnt worth it, eventually hopefully no one will notice if theres other things going on to take their mind off minor glitches. Sometimes the ghosts actually work in my favour as can be seen if this is run:-

4BLOKSPRITE.sna

10 CLS
20 PRINT AT 10,10; "Press s to STOP"
30 FOR x=1 TO 30 STEP 1
40 PRINT AT 1,x;" AB "
50 PRINT AT 2,x;" CD "
60 PAUSE 5
70 IF x=30 THEN GOTO 10
80 IF INKEY$="s" THEN STOP
90 NEXT X
dfzx
Manic Miner
Posts: 673
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: How to erase without flicker?

Post by dfzx »

Well intentioned as they are, I don't think people trying to push you towards machine code or hacks that clear the previous position with a preceding space are quite what you're after.

Try to think clearly about what you want to do. I would suggest that this psuedo-code is roughly what you're after:

Code: Select all

new_x,new_y = 10,10
print sprite at new_x,new_y

loop:
  old_x,old_y = current sprite position
  decide where you want the sprite to move to
  new_x,new_y = newly decided sprite position
  print a space at old_x,old_y
  print the sprite at new_x,new_y
  loop back to loop:
So start the sprite character at 10,10, then decide where you want it to move to (based on user input or just your simple left-to-right loop for starters). That gives you a new x,y position. Then print a space over the top of the current character to remove it, then print the character in the new location.

Then go round again: note where the character currently is, decide where you want it, then print a space over it to remove it and print it again in its new place. Repeat.

Once you can see what this is doing, convert it to BASIC. :)
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: How to erase without flicker?

Post by llewelyn »

Nicely explained dfzx - thank you.

You are quite correct about the machine code aspect. I have tried and tried, read books, watched video instructions about it but the sad fact of the matter is that I cannot get my head around it and believe me I have tried!

Which is fine, I'm just a dabbler doing a spot of Basic problem solving for the enjoyment of it. I have no ambition to advance beyond Basic and its only because of its Basic that I remain so fond of the machine - emulator - I wish it was a genuine rubber key 48k Mk1 Speccy.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: How to erase without flicker?

Post by llewelyn »

Okay this is a development from the original moving blob. Nothing to write home about really although it took me 8 hours to work out the UDG's and then arrange them to get a moving - staying in one spot but the tracks move - Mk 1 tank! I hope to have it able to move according to keyboard input later, probably take me a couple more days.

Its a .SNA file that has to be downloaded and run in your emulator or machine of choice.

http://s000.tinyupload.com/index.php?fi ... 9323534450
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: How to erase without flicker?

Post by R-Tape »

Nice wee (not so wee!) UDG tank.

Drawing the tank is a bit cumbersome though & it'll become a pain if you develop the idea.

I'd suggest storing the tank top and bottom as strings, then you can print with a lot less code.

LET TY=8:LET TX=8

LET A$="ABCD":LET B$="EFGH":LET C$="IJKL"

Then to print the tank you can do this:

PRINT AT TY,TX;A$;AT TY+1,TX;B$;

then you can move the tank by manipulating TY,TX.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: How to erase without flicker?

Post by llewelyn »

Thanks R-Tape! I'll give that a test to see how it works.

UDG design can be a real test of patience. What looks good on graph paper doesnt appear like that on screen because of its being so tiny you often have to exaggerate features enough to make them visible. Yet on graph paper it can look really awful, you can hardly make out what it is.

I used BASin to draw them and I wrote the print at code in BASin then saved it as a .sna and transferred it to Fuse which I find much easier to code with.

Before I develop the program I need to rethink the UDGs to get a better looking sprite. More detail and a bit of colour might help which means altering the placement within the character square. Trial and error takes forever.
User avatar
Joefish
Rick Dangerous
Posts: 2042
Joined: Tue Nov 14, 2017 10:26 am

Re: How to erase without flicker?

Post by Joefish »

Yep, you can also use arrays to store how the tank looks going in different directions. But remember that a string is already an array (of characters). So if you want an array with 2 different 'looks', 2 rows of UDGs, and each one 4 characters long, that's a 2x2x4 3-dimensional array.
Post Reply