Code archives/Miscellaneous/Zooming In/Out
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Cool for space games, zoom in out of the action. All you do is apply +newscale to any setscale command. For example. setscale(1.0 + newscale, 1.0 + newscale) drawimage (image, x,y) setting 1.0 always ensures the image loads at its normal scale, and only applies newscale based on how much you zoom in or out with the mouse wheel. 1.0 could even by a variable. like DefaultScale. Default_Scale = 1.0 setscale (default_scale + newscale, default_scale + newscale) so you could have different variables for different images if you want them loaded bigger or smaller by default. The zoom has a little catch up, if you scroll the wheel like 5 clicks fast, it zoom as you do that, and continue on a little after you stopped. Makes it smooth and cool 1500@... if any questions. | |||||
Strict Graphics 800,600,0 Global newscale:Float While Not KeyHit(KEY_ESCAPE) Cls SetColor(244,122,134) SetScale(1.0 + newscale,1.0 + newscale) 'handle cube by the centre SetHandle(50,50) DrawRect(400,300,100,100) 'call function zoomcamera() Flip Wend Function ZoomCamera() Local MaxZoom:Float = 3.0 Local minzoom:Float = -0.8 Local speed:Float = 0.03 Local set_Zoom:Float Local zoom 'mouse wheel value = to variable zoom zoom = MouseZ() 'so that it doesn't zoom in whole numbers( which wouldn't be smooth) set_Zoom = 0.2 * zoom 'limit max zoom in If set_Zoom > maxZoom Set_Zoom = maxZoom End If 'zooms to the set zoom value(determined by how much you scroll) If KeyDown(KEY_Z) = 0 And set_Zoom > newScale newscale :+ speed End If 'same as above If KeyDown(KEY_X) = 0 And set_Zoom < newScale newscale :- speed End If 'limit zoom out If newscale < minZoom newscale = minZoom End If setscale(1.0,1.0) DrawText("Newscale: "+newscale,100,100) End Function |
Comments
| ||
can an admin delete the .BB one, this is BMax code. also i put it in miscellaneous but that didn't look right, so i put it in algorithms... the one in miscellaneous can go, and the .bb one in here, the bmx one can stay :) |
Code Archives Forum