Mouse Trails with dynamic sprites and a timer? **SOLVED**

Started by Knox, Sat 23/10/2010 04:27:59

Previous topic - Next topic

Knox

Ok, I found these threads but it didnt quite answer what Im searching for:

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=40332.0
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=35864.0
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=11100.0

Is it possible (and not too laggy) to create a mouse trail effect "on the fly" with whatever the current mouse cursor graphic is? Im guessing the best and fastest way is with dynamic sprites, right? Is there any way I can do this without creating characters that follow the mouse? Id rather not create multiple individual characters or gui's for the trail effect (if possible).

I thought maybe have a timer + store the mouse cursor's position and then redraw the 4 trail cursors "1,2,3,4" at the main cursor's previous position "x" loops ago + then fading out that dynamic sprite x loops later...(and off-setting each trail graphic with different x or y values + opacities, depending on the mouse's direction)?

Im guessing (without trying it just yet) it might be too much...I have a tendency to over-complicate things, anyone have a simpler idea?
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

The problem with the DynamicSprite approach is a quirk in AGS's way of handling transparency.
If you draw a semi-transparent sprite onto an empty DynamicSprite, its color values are blended into pink (255, 0, 255).

There are two ways to overcome this.
The first is to draw everything yourself every game loop, i.e. background, characters, objects, mouse sprites on top. This is only reasonable if the whole screen is drawn on the fly anyway (think tile engine).

The other way unfortunately is indeed to use GUIs or characters.
I doesn't feel clean, and I was a bit frustrated with having to do that myself, but afaik, currently it's the only way.
The advantage is that all you have to do is set the position and transparency and AGS takes care of the rest.
Personally, I'd use GUIs with appropriate consecutive zOrder values.

Calin Leafshade

AGSBlend could happily do this.

Just make a dynamic sprite the size of the screen (for ease... if you wanted you could optimise this with trickery)
use AGSBlend to draw progressively fainter versions of your mouse pointer sprite onto your screen sprite allowing for the displacement of the mouse.
finally apply your screen sprite to a gui or overlay.

I can rustle up some code if you like.

tzachs

Perhaps the particle engine module could be of assistance to you.
Look at the demo, one of the samples is of particles surrounding the mouse, and I think you would be able to tweak it (with some trial and error) to do what you want.

Wyz

I used this function once to do something similar. I drew it directly to the background and drew the background image over it to make it fade, but I think you can also use Calin's plugin for that.

offtopic:
I heard some rumors the transparency issues were fixed in the new version, is that true?
Life is like an adventure without the pixel hunts.

Knox

Oh wow, so many options...cool!  :D

Ok,well I look into all of those to see what I can come up with...if Im still stuck Ill let you guys know :P

--All that is necessary for evil to triumph is for good men to do nothing.

Knox

Ok well I had A LOT of fun screwing around with your code Wyz! Heheh...drawing the mouse's cursor everywhere onto the background for the hell of it is quite addictive :P

Ok, well I got to the point where (in rep_exec) with mouse movement, I have a bit of a wiggle with randomness around the cursor, and it draws on the background OK...step 1 is done :)

Code: ags

  //this will draw cursor onto background with mouse movement
  CursorMode mode = mouse.Mode;
  int iSprite = mouse.GetModeGraphic(mode);
  surface = Room.GetDrawingSurfaceForBackground();
  int iRandX = RandomBoundries(-20, 20);
  int iRandY = RandomBoundries(0, 40);
  surface.BrushLine(mouse.x+iRandX , mouse.y+iRandY, mouse.x, mouse.y, iSprite, 4.0);
  surface.Release();


For step 2, I was thinking I create a 200x200 gui named "gTrailGuiZone" (that frames the mouse cursor to give enough space for the trail) with a dynamic sprite as its background image, and that gui follows the mouse. Then, I can grab that 200x200 zone around the mouse, draw the trail onto it with Wyz's script and fade out each time so that after x loops, the trail dies off (and regenerates itself until the effect is turned off). The problem with my above code is that it draws onto the background so the cursor trail will show up behind characters and objects...it would be great to draw on top of that, so Im guessing we'd need to do a partial screen-grab of the "gTrailGuiZone" within the bounderies (mouse.x - 200, mouse.x + 200, mouse.y - 200, mouse.y + 200 ) and paste that into its dynamic sprite.

This, I admit, is beyond my limited beginner skills!

So, uh, yeah Calin, rustle it up bay-bayh!
;D
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

here you go: http://www.thethoughtradar.com/AGS/MouseTrails.scm

Requires AGSBlend.

But this has exposed a bug in AGSBlend but I dont have the source with me so its not fully functional but it will be once I update the plugin which i shall do this evening i hope.

Knox

WOW!

I was NOT expecting something of this high-quality, holy geeze! haha, man...!

Well, thanks a lot again, its absolutely perfect!  :)
--All that is necessary for evil to triumph is for good men to do nothing.

Knox

#9
Hey Calin,

Any news on the AGSBlend + MouseTrails update?

Ive got 2 questions for you (if you have the time of course :))

Somehow, while testing the trails, the mousetrails got "baked" into the background. I only was able to do this once (Im trying to reproduce this bug but cant seem to reproduce)...do you know how this could have happened? If so, is there a way we can add a feature in the MouseTrails to check if this happens, to erase it from the background? As in:

Pseudo-code:
Code: ags

if (mouseTrails get baked to background by accident) clearMouseTrails();


Thanks ;D
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk