Author Topic: Mouse Trail  (Read 3164 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Mouse Trail
« on: December 09, 2019, 12:26:56 am »
I believe many months ago someone made something like this, but I thought I would freshen my memory. This is a small example of how to make your mouse pointer have a trail. Use your mouse wheel to increase and decrease the size of it. Thanks to b+ who once showed me how to make a fading trail.

Code: QB64: [Select]
  1. _TITLE "Mouse Trail - Use Mouse Wheel to change size."
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.     _LIMIT 50
  4.     mouseWheel = 0
  5.         mouseX = _MOUSEX
  6.         mouseY = _MOUSEY
  7.         mouseLeftButton = _MOUSEBUTTON(1)
  8.         mouseRightButton = _MOUSEBUTTON(2)
  9.         mouseMiddleButton = _MOUSEBUTTON(3)
  10.         mouseWheel = mouseWheel + _MOUSEWHEEL
  11.     LOOP
  12.     IF mouseWheel > 0 THEN mwheel = mwheel + 5
  13.     IF mouseWheel < 0 THEN mwheel = mwheel - 5
  14.     IF mwheel < 1 THEN mwheel = 1
  15.     IF mwheel > 300 THEN mwheel = 300
  16.     CIRCLE (mouseX, mouseY), mwheel, _RGB32(0, 255, 0)
  17.     PAINT (mouseX, mouseY), _RGB32(0, 255, 0)
  18.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA(0, 0, 0, 30), BF
  19.     _DISPLAY
  20.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mouse Trail
« Reply #1 on: December 09, 2019, 03:23:36 am »
Wouldn’t this be an excellent case of using multiple screens for your work?

DisplayScreen = _NEWIMAGE(800, 600, 32)
WorkScreen = _NEWIMAGE(800, 600, 32)
MouseScreen = _NEWIMAGE(800, 600, 32)

SCREEN DisplayScreen

DO
    _SOURCE WorkScreen: _DEST WorkScreen
    ‘Draw on your work screen
    _SOURCE  MouseScreen
    ‘Draw the mouse trails
    _PUTIMAGE , WorkScreen, DisplayScreen
    _PUTIMAGE , MouseScreen, DisplayScreen
LOOP


Then you’d preserve the original screen while being able to fade out the trails that your mouse poops out behind itself.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Mouse Trail
« Reply #2 on: December 09, 2019, 10:59:46 am »
OMG! I CAN'T GET AWAY FROM IT!  ;)

Nice job there. I'll be studying this one for future reference.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mouse Trail
« Reply #3 on: December 09, 2019, 11:18:21 am »
Ha, yeah learned that from Fellippe's fireworks I think and then warping through the stars. I was trying to do those trails without alpha fading (but I can do with different colors).

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Mouse Trail
« Reply #4 on: December 09, 2019, 04:16:53 pm »
Thanks everyone. I just made my own Cats and Mouse game using this code. SMMcNeil, I also used your code, thanks! I'm going to make a new thread for my new game.