Smooth Scrolling With The Mousewheel
Blitz3D Forums/Blitz3D Beginners Area/Smooth Scrolling With The Mousewheel
| ||
Hiya! I've been having all sorts of nightmares with getting smoother scrolling up and down with using the mouse wheel. When saying smoother, I mean the image scrolls according to how fast the mouse wheel is moved. As you'll see from the example below it's not right. And would love help me getting it working correctly. Cheers so much! ;-========================- ;-=[Mouse Scroll Wheel ]=- ;-=[Moving Image Program]=- ;-========================- Const xres=640,yres=480 Graphics xres,yres SetBuffer BackBuffer() Global Scroll_Image=CreateImage(xres-100,1000) SetBuffer ImageBuffer(Scroll_Image) Color 164,000,000 Rect 100,0,xres-100,yres,1 For Bits=0 To Rnd(200) Color Rnd(60,250),Rnd(60,255),Rnd(60,255) Rect Rnd(100,xres),Rnd(0,yres),Rnd(4,20),Rnd(4,20) Next SetBuffer BackBuffer() Global MY# While Not KeyHit(1) Cls Update_Image_With_Scroll_Wheel() Flip Wend Function Update_Image_With_Scroll_Wheel() MY=MouseZ()+MouseZSpeed() ;-============================- ;-=[Draw And Move The Screen]=- ;-============================- DrawImage Scroll_Image,0,MY End Function |
| ||
Is this what you mean?;-========================- ;-=[Mouse Scroll Wheel ]=- ;-=[Moving Image Program]=- ;-========================- Const xres=640,yres=480 Graphics xres,yres SetBuffer BackBuffer() Global Scroll_Image=CreateImage(xres-100,1000) SetBuffer ImageBuffer(Scroll_Image) Color 164,000,000 Rect 100,0,xres-100,yres,1 For Bits=0 To Rnd(200) Color Rnd(60,250),Rnd(60,255),Rnd(60,255) Rect Rnd(100,xres),Rnd(0,yres),Rnd(4,20),Rnd(4,20) Next SetBuffer BackBuffer() Global MY# While Not KeyHit(1) Cls Update_Image_With_Scroll_Wheel() Flip Wend Function Update_Image_With_Scroll_Wheel() MY=MY + MouseZSpeed()*10 ;-============================- ;-=[Draw And Move The Screen]=- ;-============================- DrawImage Scroll_Image,0,MY End Function |
| ||
or are you looking for something like this:;-========================- ;-=[Mouse Scroll Wheel ]=- ;-=[Moving Image Program]=- ;-========================- Const xres=640,yres=480 Graphics xres,yres SetBuffer BackBuffer() Global Scroll_Image=CreateImage(xres-100,1000) SetBuffer ImageBuffer(Scroll_Image) Color 164,000,000 Rect 100,0,xres-100,yres,1 For Bits=0 To Rnd(200) Color Rnd(60,250),Rnd(60,255),Rnd(60,255) Rect Rnd(100,xres),Rnd(0,yres),Rnd(4,20),Rnd(4,20) Next SetBuffer BackBuffer() Global MY# Global lastupdate = MilliSecs() While Not KeyHit(1) Cls Update_Image_With_Scroll_Wheel() Flip False Wend Function Update_Image_With_Scroll_Wheel() action = MouseZSpeed() If action <> 0 thisupdate = MilliSecs() Else thisupdate = lastupdate EndIf timeelapsed = (thisupdate - lastupdate) / 10 If timeelapsed > 20 Then timeelapsed = 20 MY=MY + action*(21 - timeelapsed) ;-============================- ;-=[Draw And Move The Screen]=- ;-============================- DrawImage Scroll_Image,0,MY lastupdate = thisupdate End Function |
| ||
Fabulous Mate, thanks! :) |
| ||
Also, how would I add in to the routine a limit - so that it doesn't scroll and register the scroll wheel moving when and if the top and bottom of the image is scrolled to it's boundary? Thank ever so much :) |
| ||
Well, you don't need my help to do that. Just don't allow MY# to be any larger or smaller than a certain value. It's not as hard as you think. |
| ||
What about this:;-========================- ;-=[Mouse Scroll Wheel ]=- ;-=[Moving Image Program]=- ;-========================- Const xres=640,yres=480 Graphics xres,yres SetBuffer BackBuffer() Global Scroll_Image=CreateImage(xres-100,1000) SetBuffer ImageBuffer(Scroll_Image) Color 164,000,000 Rect 100,0,xres-100,yres,1 For Bits=0 To Rnd(200) Color Rnd(60,250),Rnd(60,255),Rnd(60,255) Rect Rnd(100,xres),Rnd(0,yres),Rnd(4,20),Rnd(4,20) Next SetBuffer BackBuffer() Global MY#,MRY# Global lastupdate = MilliSecs() While Not KeyHit(1) Cls Update_Image_With_Scroll_Wheel() Flip False Wend Function Update_Image_With_Scroll_Wheel() action = MouseZSpeed() If action <> 0 thisupdate = MilliSecs() Else thisupdate = lastupdate EndIf timeelapsed = (thisupdate - lastupdate) / 10 If timeelapsed > 20 Then timeelapsed = 20 MY=MY + action*(21 - timeelapsed) MRY=MRY+(MY - MRY)/100 ;-============================- ;-=[Draw And Move The Screen]=- ;-============================- DrawImage Scroll_Image,0,MRY lastupdate = thisupdate End Function |