Moving the light
BlitzMax Forums/BlitzMax Programming/Moving the light
| ||
Hi guys! I've been experimenting with the light sample in the Blitz dir. Its the one that show an expanding and shrinking white light where your mouse is, across a blue moving Blitzmax backdrop. I adjusted the code to make just a growing, but not shrinking light, over and over, like this: (tim# is initially set to 0, so goes to 180, which seems to be the smallest (or biggest?) circle size.) SetBlend LightBlend SetColor (255,155,155) ' neat reddish hue tim = tim - 1 'lightx = lightx - 1.5 + (1.5+1*Cos(tim)) ?? 'lighty = lighty - 3 ?? If tim <= 0 Then tim = 180 lightx = 345 lighty = 334 End If SetScale 1.5+1*Cos(tim), 1.5+1*Cos(tim) DrawImage lightimage, lightx,lighty SetColor (255,255,255) SetBlend MaskBlend SetScale(1,1) So I have the light in the center of my screen 345,334, to grow around a character I have as part of some sort of magic effect. The trouble is the lightx and lighty position. If I give them absolute values, like lightx = lightx - 2 or something, the expanding light tends to wobble left and right, up and down. I think I don't understand cosine too well. :) It seems like the values for the x and y must vary as the circle expands, probably based on the scale ratio with the cosine in it somehow. My goal is that the light expands around my character - always in the center of the screen, but equally and smoothly in all directions. Any clarification of how this could be done would be appreciated. Thanks again, -Rob |
| ||
I meant to say that the increment for the x and y must vary somehow. |
| ||
if the image is an actual image, can't the image be expanded from the centre equally outwards just by using setscale? If not I am understanding wrong and blame my noobness. Set your program for automidhandle |
| ||
Hiya Keeping things with the original example code... To make the light repeatedly scale up only, you need to change line 54 to scale the other way by taking the value away instead of adding it to the scale. To limit it to just going from small to big you would use Mod operator with the 'tim' variable to limit it to be 0 : 180 ( the example just lets the value increase to 'potential' infinity ) :- Line 54 tim = tim Mod 180 ' Add this line here. Limit to ratios of 0 : 180 SetScale 1.5-1*Cos(tim), 1.5-1*Cos(tim) ' Change the '+' to '-' Then you can use that to incorporate into your own code, then go check out some online trigonometry tutorials... they look really hard and confusing at first but they will be your best friend once you get your head around them :-) One thing that may trip you up is that BlitzMax trig functions Cos,Sin etc use degrees, whereas you may find most tutorials will use radians. Again don't be afraid to learn the difference. Its a simple function to change from one to the other. Radians go from 0 to 2*pi ( 0 to 2*3.14159.....) and degrees from 0 to 360 ). Hope this helps. Last edited 2013 |