Sver
Full Member
Posts: 145
|
Post by Sver on Dec 14, 2019 6:19:18 GMT -5
nomainwin
graphicbox #main.draw, 10, 10, 150, 150
button #main.but1, "<", [left], UL, 10, 180, 50 , 50
button #main.but2, ">", [right], UL, 100, 180, 50 , 50
open "example" for window as #main
#main,"trapclose [close]"
loadbmp "aBitmap", "mickey.bmp"
wait
[close]
close #main
end
'-------------------------------------------------------------------------
[left]
print #main.draw, "cls"
print #main.draw, "drawbmp aBitmap ";x;" ";y
if x=-210 then x=150
x=x-1
timer 20, [k]
wait
[k]
timer 0
goto [left]
'-------------------
[right]
print #main.draw, "cls"
print #main.draw, "drawbmp aBitmap ";x;" ";y
if x=150 then x=-210
x=x+1
timer 20, [p]
wait
[p]
timer 0
goto [right]
Of course, there is a better way whitout flickering , but how? Thanks
|
|
|
Post by Rod on Dec 14, 2019 7:18:56 GMT -5
There are two techniques to reduce the flashing. The first is to use the drawing rule xor to draw over and erase the bmp. The second and probably better option is to use the sprite engine. Windows no longer allows programs access to the screen refresh event. Windows controls how all windows are updated and redrawn so we loose the old sync we used to have with older OS's
Now with rule over/xor you will see much less flashing, mainly caused by the cls command. It makes a big drawing change which often cannot be completed in time so the screen refresh interrupts the drawing. What you will see is a variable rate of crawl, this is because window picks and chooses when it gives us time and so alters the pace of drawing.
If you moved to sprites it would all be more stable because the sprite engine draws things relatively quickly to a buffer and blips it into view with drawsprites. The screen refresh rarely interrupts it.
Here is the xor/over solution. The default drawing rule is OVER, provided you have drawn it once with OVER then a redraw in exactly the same position with XOR will erase the drawing leaving the background in place.
nomainwin graphicbox #main.draw, 10, 10, 150, 150 button #main.but1, "<", [left], UL, 10, 180, 50 , 50 button #main.but2, ">", [right], UL, 100, 180, 50 , 50 open "example" for window as #main #main,"trapclose [close]"
'load and display bmp record oldx oldy loadbmp "aBitmap", "cherry.bmp" x=50 y=50 oldx=50 oldy=50 #main.draw, "down ; rule over ; drawbmp aBitmap ";x;" ";y wait
[close] close #main end
[left] timer 0 #main.draw, "rule xor ; drawbmp aBitmap ";oldx;" ";oldy if x<-100 then x=151 x=x-1 #main.draw, "rule over ; drawbmp aBitmap ";x;" ";y oldx=x oldy=y timer 20, [left] wait
[right] timer 0 #main.draw, "rule xor ; drawbmp aBitmap ";oldx;" ";oldy if x>150 then x=-100 x=x+1 #main.draw, "rule over ; drawbmp aBitmap ";x;" ";y oldx=x oldy=y timer 20, [right] wait
|
|
|
Post by Rod on Dec 14, 2019 7:33:05 GMT -5
And this is a sprite example, there are easily absorbed sprite tutorials on the LBPE.
nomainwin graphicbox #main.draw, 10, 10, 150, 150 button #main.but1, "<", [left], UL, 10, 180, 50 , 50 button #main.but2, ">", [right], UL, 100, 180, 50 , 50 open "example" for window as #main #main,"trapclose [close]"
'load bmp add sprite and background and show the result 'for sprites the bmp has to be masked there is a utility that ships with Liberty loadbmp "aBitmap", "smiley1.bmp" #main.draw "down ;fill green;getbmp bac 0 0 150 150 ;background bac" #main.draw "addsprite s aBitmap ; spritexy s 50 50" #main.draw "drawsprites" x=50 y=50
wait
[close] close #main end
[left] timer 0 if x<-51 then x=151 x=x-1 #main.draw "spritexy s ";x;" ";y #main.draw "drawsprites" timer 20, [left] wait
[right] timer 0 if x>150 then x=-51 x=x+1 #main.draw "spritexy s ";x;" ";y #main.draw "drawsprites" timer 20, [right] wait
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Dec 14, 2019 8:43:37 GMT -5
Thanks for the quick response !
I was looking for the first option. In my case, enough.
|
|
|
Post by tsh73 on Dec 14, 2019 9:10:24 GMT -5
I'm sorry to say but native LB "RULE XOR" works only on drawn objects (point line circle etc) Doesn't work for DRAWBMP and, I believe, for text.
Your code works just because of wide white border on picture.
May be there is some API trick to turn such behavior?
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Dec 14, 2019 10:05:27 GMT -5
I'm sorry to say but native LB "RULE XOR" works only on drawn objects (point line circle etc) Doesn't work for DRAWBMP and, I believe, for text. Your code works just because of wide white border on picture. May be there is some API trick to turn such behavior? Yes, when there isn't a white thin border, i'll get a black vertical line, when the picture moved to the right. I painted a few pixel white and it works well.
|
|
|
Post by Rod on Dec 14, 2019 11:41:46 GMT -5
Yes, sorry bmp drawing has no need of XOR drawing. Provided it has a background color border you can simply move it a pixel and redraw. The wider the border the further it can move in a single step. nomainwin graphicbox #main.draw, 10, 10, 150, 150 button #main.but1, "<", [left], UL, 10, 180, 50 , 50 button #main.but2, ">", [right], UL, 100, 180, 50 , 50 open "example" for window as #main #main,"trapclose [close]"
'load and display bmp loadbmp "aBitmap", "test.bmp" x=50 y=50 #main.draw, "down ;fill blue; drawbmp aBitmap ";x;" ";y wait
[close] close #main end
[left] timer 0 if x<-100 then x=151 x=x-1 #main.draw, "drawbmp aBitmap ";x;" ";y oldx=x oldy=y timer 20, [left] wait
[right] timer 0 if x>150 then x=-100 x=x+1 #main.draw, "drawbmp aBitmap ";x;" ";y oldx=x oldy=y timer 20, [right] wait
You can use the blitter to draw bmps transparently but that's a lot of code if you just want to scroll a bmp. Again you will find blitter lessons on the LBPE
|
|