|
Post by chad3006 on Apr 13, 2020 12:01:32 GMT -5
I need to know how to accelerate a background from 0 to some maximum number, smoothly. I've modified some existing LB code but it has a constant movement rate.
nomainwin WindowWidth=410 WindowHeight=340 graphicbox #w.g, 0,0,400,300 open "Window" for window_nf as #w
loadbmp "landscape", "SPRITES\bg1.bmp"
print #w.g, "background landscape"; print #w, "trapclose [quit]" timer 100,[scroll] wait [scroll] x=x+5:y=y+0 print #w.g, "backgroundxy ";x;" ";y print #w.g, "drawsprites" [loop] wait [quit] close #w end
|
|
|
Post by Rod on Apr 13, 2020 13:19:53 GMT -5
nomainwin WindowWidth=410 WindowHeight=340 graphicbox #w.g, 0,0,400,300 open "Window" for window_nf as #w
loadbmp "landscape", "c:\basic\sprites\bg1.bmp"
#w.g "background landscape"; #w "trapclose [quit]" #w.g "when characterInput [speed]" #w.g "setfocus" speed=.25 timer 100,[scroll] wait
[scroll] x=x+speed:y=y+0 #w.g "backgroundxy ";x;" ";y #w.g "drawsprites" wait
[speed] k$=right$(Inkey$,1) if k$=chr$(_VK_LEFT) then speed = speed -.25 if k$=chr$(_VK_RIGHT) then speed = speed +.25 if speed <-10 then speed =-10 if speed >10 then speed =10 wait
[quit] close #w end
|
|
|
Post by chad3006 on Apr 13, 2020 13:52:49 GMT -5
Thanks Rod. If I understand this correctly, it accelerates at 25% to a maximum of 10, is that right?
|
|
|
Post by Rod on Apr 13, 2020 14:48:03 GMT -5
Yep, you can set limits and change the step change value. The change I post is linear, you can of course change the speed on a logarithmic basis. But doubling the change, while natural, is hard to accommodate in such few pixels as we show. No right or wrong answer, experiment and see what works for you.
|
|