Page 1 of 1

### Sprite flicker problem

Posted: Sat Oct 06, 2007 4:45 pm
Okay folks, I'm going to be working on a game with sprites in screen 13. I wrote a short program to practice the techniques on, but I get flicker. I've read that to get rid of flicker you use the WAIT &h3da, 8 line, but it didn't help me. In fact, when I used the above line once before the sprite PUT and once before the background PUT (sprite erase), it make the sprite look positively translucent while it was moving!

So basically what I want to know is: a) am I using this method correctly? or b) is there another method I should be using?

Here is my program:

Code: Select all

``````DIM sprite(515) AS INTEGER
SCREEN 13
RANDOMIZE TIMER

LINE (0, 0)-(15, 31), 12, BF
GET (0, 0)-(15, 31), sprite(0)

CLS

FOR lines = 1 TO 255
x1 = INT(RND * 320): y1 = INT(RND * 200)
x2 = INT(RND * 320): y2 = INT(RND * 200)
LINE (x1, y1)-(x2, y2), lines
NEXT lines

x = 150: y = 80

DO
oldX = x: oldY = y
GET (x, y)-(x + 15, y + 31), sprite(258)
WAIT &H3DA, 8
PUT (x, y), sprite(0), PSET

DO: k\$ = INKEY\$: LOOP WHILE k\$ = ""

IF k\$ = "4" THEN
x = x - 2: IF x < 0 THEN x = 320 - 16
END IF
IF k\$ = "6" THEN
x = x + 2: IF x > 320 - 16 THEN x = 0
END IF
IF k\$ = "8" THEN
y = y - 2: IF y < 0 THEN y = 200 - 32
END IF
IF k\$ = "2" THEN
y = y + 2: IF y > 200 - 32 THEN y = 0
END IF
PUT (oldX, oldY), sprite(258), PSET
LOOP UNTIL k\$ = CHR\$(27)

SYSTEM
``````

Posted: Sat Oct 06, 2007 8:00 pm
you just had the wait in the wrong place

Code: Select all

``````DIM sprite(515) AS INTEGER
SCREEN 13
RANDOMIZE TIMER

LINE (0, 0)-(15, 31), 12, BF
GET (0, 0)-(15, 31), sprite(0)

CLS

FOR lines = 1 TO 255
x1 = INT(RND * 320): y1 = INT(RND * 200)
x2 = INT(RND * 320): y2 = INT(RND * 200)
LINE (x1, y1)-(x2, y2), lines
NEXT lines

x = 150: y = 80

DO
oldX = x: oldY = y
GET (x, y)-(x + 15, y + 31), sprite(258)
PUT (x, y), sprite(0), PSET

DO: k\$ = INKEY\$: LOOP WHILE k\$ = ""

IF k\$ = "4" THEN
x = x - 2: IF x <0> 320 - 16 THEN x = 0
END IF
IF k\$ = "8" THEN
y = y - 2: IF y <0> 200 - 32 THEN y = 0
END IF
WAIT &H3DA, 8

PUT (oldX, oldY), sprite(258), PSET
LOOP UNTIL k\$ = CHR\$(27)

SYSTEM

``````

Posted: Sat Oct 06, 2007 9:07 pm
Thanks Nixon. It's better, but there's still some flicker going on, especially when I hold down a key to move continuously. Is there nothing I can do about that?

Posted: Sat Oct 06, 2007 10:32 pm
hmm thats odd because I'm not getting any flicker when I move it. Sorry but I can't really help if I can't see the problem. I would suggest to just try moving things around in your code. You should be able to get rid of it.

### try this

Posted: Sat Oct 06, 2007 10:37 pm
Theophage wrote:Is there nothing I can do about that?

Code: Select all

``````DIM sprite(515) AS INTEGER
SCREEN 13
RANDOMIZE TIMER

LINE (0, 0)-(15, 31), 12, BF
GET (0, 0)-(15, 31), sprite(0)

CLS

FOR lines = 1 TO 255
x1 = INT(RND * 320): y1 = INT(RND * 200)
x2 = INT(RND * 320): y2 = INT(RND * 200)
LINE (x1, y1)-(x2, y2), lines
NEXT lines

x = 150: y = 80
GET (x, y)-(x + 15, y + 31), sprite(258)
PUT (x, y), sprite(0), PSET
DO
DO
DO: k\$ = INKEY\$: LOOP WHILE k\$ = ""
LOOP WHILE INSTR("2468" + CHR\$(27), k\$) = 0
if k\$=chr\$(27) then exit do
Newx=x: Newy=y
SELECT CASE VAL(k\$)
CASE 4: Newx = x - 2: IF Newx < 0 THEN Newx = 320 - 16
CASE 6: Newx = x + 2: IF Newx > 320 - 16 THEN Newx = 0
CASE 8: Newy = y - 2: IF Newy < 0 THEN Newy = 200 - 32
CASE 2: Newy = y + 2: IF Newy > 200 - 32 THEN Newy = 0
END SELECT
WAIT &H3DA, 8
PUT (x, y), sprite(258), PSET
x=Newx: y=Newy
GET (x, y)-(x + 15, y + 31), sprite(258)
PUT (x, y), sprite(0), PSET
WAIT &H3DA, 8,8
LOOP
SYSTEM
``````

Posted: Sat Oct 13, 2007 9:35 pm
Since Mac rebuked me in the other thread for not giving proper acknowledgement, I thought I would make it known that I hadn't gotten as far as implementing his change to my program since I completely changed how my program was going to work. I started the other thread because I hadn't even gotten the revised program far enough to worry about flicker again before running into a problem.

When I do get that far, I will adopt Mac's solution (which seems to be placing the WAIT statement before every PUT) and post the results here. Thank you all for your patience (or lack thereof...)

Posted: Sat Oct 13, 2007 10:49 pm
[quote="Theophage"]Mac's solution (which seems to be placing the WAIT statement before every PUT)[/quote]

My suggestion, in words, rather than code, is to put
WAIT &H3DA, 8
before you start messing with the screen and
WAIT &H3DA, 8,8
after you are finished.

If you never come back to see this thread, fine. Maybe some researcher of the future will see this hint.

Mac

Posted: Sun Oct 14, 2007 1:48 pm
Or, you could try to use a graphics library like GSLib or RELLlib. You will not experience anymore flickering and it's very easy to use.

### SNARK LOL

Posted: Wed Oct 31, 2007 6:24 pm
Might as well call him a SNARK!

He is absolutely rude about giving thanks!