Follow Cursor

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Follow Cursor

Post by bidgeeman » Tue Aug 18, 2009 3:29 am

Hello.
Trying to find in the Rev dictionary where you can set, say an image, to follow the cursor. Can someone please help direct me to the correct area for this?

Many thanks
Bidge

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Tue Aug 18, 2009 8:57 am

Hi Bidge,

check "mousemove" in the docs (=Rev Dictionary), which will be the most efficient way to do this.

Example, maybe in the card script:

Code: Select all

on mousemove x,y
  set the loc of img "little image" to x,y
end mousemove
Best

Klaus

bidgeeman
Posts: 495
Joined: Wed Feb 21, 2007 7:58 am

Post by bidgeeman » Tue Aug 18, 2009 9:00 am

Oh...thank you very much Klaus for your help once again :)

Cheers
Bidge

kelyanok
Posts: 22
Joined: Sun Feb 23, 2020 8:48 am

Re: Follow Cursor

Post by kelyanok » Tue Mar 03, 2020 12:58 pm

hello klaus!

your code is working perfectly well, but im trying to make it like the image is following the mouse but not right on it, like... its difficult to explain... the image needs to be at the location where the mouse was 1 sec ago. i wonder if you understand but thank you in advance! :D

oh and can you help me im trying to make that my player is following my mouse by rotating, without moving. im asking to much question goobye

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Follow Cursor

Post by dunbarx » Tue Mar 03, 2020 2:58 pm

Hi.

LiveCode is SO much fun.

On a new card make a button. In the card script:

Code: Select all

local mouseTrack

on mouseMove
   put the mouseLoc & return after mouseTrack
   set the loc of btn 1 to line -10 of mouseTrack
end mouseMove
Move the cursor around the screen.

The number "10" is arbitrary. There is no particular relationship with actual time in this, but could be implemented if you really need to. I assumed that you just wanted the control to follow at a certain distance behind the cursor.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Follow Cursor

Post by dunbarx » Tue Mar 03, 2020 3:16 pm

Hi again.

Remember that "fun" thing? There are things you can do with this to make it better. For example, if you move the cursor quickly and then stop, the button will track but then halt ten messages behind. Did you want it to catch up?

Get going.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 3:59 pm

Of course that throws a "bluey" because until there are 10 lines in mouseTrack you
get a can't set object property notice.
-
bluey1.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 4:28 pm

Most of the problem boils down to 2 things:

1. You need to populate the first 10 lines of your mouseTrack local.

2.You need to put return before and NOT after the loc.

Code: Select all

local Lyne
local mouseT

on preOpenCard
   put 1 into Lyne
   repeat until Lyne > 11
      put "350,350" into line Lyne of mouseT
      add 1 to Lyne
   end repeat
end preOpenCard

on mouseMove xx,yy
   put return & (xx,yy) after mouseT
   add 1 to Lyne
   set the loc of img "monster.png" to line (Lyne -10) of mouseT
end mouseMove
-
Attachments
Monster.livecode.zip
Here's the stack.
(16.04 KiB) Downloaded 239 times
monsterStack.png

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Follow Cursor

Post by dunbarx » Tue Mar 03, 2020 4:37 pm

Richmond.
Of course that throws a "bluey" because until there are 10 lines in mouseTrack you
get a can't set object property notice.
Technically true, but the "queue' fills fast, so that the moment you start moving the mouse the button starts to follow. I don't think it is necessary at all to preload the list, though certainly there is nothing wrong with doing so.

Remember, this is just "fun" at the moment. We will see how this develops, and how serious the final product needs to be. A more "important" fun detail is to make the control catch up with the cursor after it has stopped moving.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 4:56 pm

Well this:

Code: Select all

local Lyne
local mouseT

on preOpenCard
   put 1 into Lyne
   repeat until Lyne > 11
      put "350,350" into line Lyne of mouseT
      add 1 to Lyne
   end repeat
end preOpenCard

on mouseMove xx,yy
   put return & (xx,yy) after mouseT
   add 1 to Lyne
   set the loc of img "monster.png" to line (Lyne -10) of mouseT
   put 9 into DC
   repeat until DC < 1
      wait 2 ticks
      set the loc of img "monster.png" to line DC of mouseT
      subtract 1 from DC
      put DC
   end repeat
end mouseMove
Is a load of cr*p because the object hops around to all the places the mouse visited
previously, while what it needs to do is to move smoothly from its last location to the current mouse location.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 5:01 pm

I think I may have been guilty of "overthinking" the problem as this works:

Code: Select all

local Lyne
local mouseT

on preOpenCard
   put 1 into Lyne
   repeat until Lyne > 11
      put "350,350" into line Lyne of mouseT
      add 1 to Lyne
   end repeat
end preOpenCard

on mouseMove xx,yy
   put return & (xx,yy) after mouseT
   add 1 to Lyne
   set the loc of img "monster.png" to line (Lyne -10) of mouseT
   set the moveSpeed to 50
   move img "monster.png" to xx, yy
end mouseMove
-
Well, up to a point:
-
bluey2.png
Attachments
Monster2.livecode.zip
Don't say you weren't warned.
(16.07 KiB) Downloaded 211 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Follow Cursor

Post by dunbarx » Tue Mar 03, 2020 5:18 pm

Richmond.

Monster 2 seems a bit, er, unsure of itself. :D

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 5:32 pm

Monster 2 seems a bit, er, unsure of itself.
Aren't we all? 8)

The main problem as far as I can see is there is no (pseudoCode) on mouseNotMoving . . .
monster.png
monster.png (15.08 KiB) Viewed 8664 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 6:00 pm

I wonder what the point of

revStackNameIsIDEStack

is, as when I dismiss that notice the script carries on functioning.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10097
Joined: Fri Feb 19, 2010 10:17 am

Re: Follow Cursor

Post by richmond62 » Tue Mar 03, 2020 6:23 pm

I suspect part of that insecurity might have being NOT using mouseLoc:

Code: Select all

local Lyne
local mouseT

on preOpenCard
   put 1 into Lyne
   repeat until Lyne > 11
      put "350,350" into line Lyne of mouseT
      add 1 to Lyne
   end repeat
   set the loc of img "Monster.png" to 350,350
end preOpenCard

on mouseMove xx,yy
   put return & (xx,yy) after mouseT
   add 1 to Lyne
   set the loc of img "monster.png" to line (Lyne -10) of mouseT
   set the moveSpeed to 200
move img "monster.png" to the mouseLoc --changed this line
   if Lyne > 20000 then
      put empty into Lyne
      send "on preOpenCard" to me
   end if
end mouseMove
Attachments
Monster 3.livecode.zip
Does it get better or worse?
(16.13 KiB) Downloaded 246 times

Post Reply