01-01-2025, 04:24 AM
For @bplus
A demo of how to keep a background from being altered, while fading out a trail behind an image. Nothing fancy here; just a simple red box that chases after your mouse and leaves a nice trail behind itself as it does so, without fading or altering the background image any whatsoever.
Code: (Select All)
Const fade = 5 'speed by which our trail disappears
Randomize Timer
Screen _NewImage(640, 480, 32)
background = _NewImage(640, 480, 32)
movescreen = _NewImage(640, 480, 32)
'let's draw a nice background of junk
_Dest background
Cls , &HFFF000F0&&
For i = 1 To 20
Line (Rnd * 100, Rnd * 100)-(Rnd * 700, Rnd * 500), _RGB32(Rnd * 256, Rnd * 256, Rnd * 256), BF
Next
'then let's swap to the movescreen and work
_Dest movescreen
Do
Cls , 0, 0
While _MouseInput: Wend
mx = _MouseX: my = _MouseY
'fade the movescreen over time
FadeScreen movescreen, fade
'update the red box position that chases the mouse slowly
x = x + Sgn(mx - x): y = y + Sgn(my - y)
'draw the solid box which chases after the mouse
Line (x, y)-Step(50, 50), &HFFFF0000, BF
'put the parts on the screen
_PutImage , background, 0
_PutImage , movescreen, 0
_Limit 60
_Display
Loop
Sub FadeScreen (s, faderate)
Dim m As _MEM, o As _Offset
m = _MemImage(s)
Dim p As _Unsigned Long
Do Until o >= m.SIZE
_MemGet m, m.OFFSET + o, p
If p <> 0 Then 'fade the point down to 0 (transparent)
r = _Red32(p) - faderate: If r < 0 Then r = 0
g = _Green32(p) - faderate: If g < 0 Then g = 0
b = _Blue32(p) - faderate: If b < 0 Then b = 0
a = _Alpha32(p) - faderate: If a < 0 Then a = 0
_MemPut m, m.OFFSET + o, _RGBA32(r, g, b, a) As _UNSIGNED LONG
End If
o = o + 4
Loop
_MemFree m
End Sub
A demo of how to keep a background from being altered, while fading out a trail behind an image. Nothing fancy here; just a simple red box that chases after your mouse and leaves a nice trail behind itself as it does so, without fading or altering the background image any whatsoever.