Page 1 of 2

Follow Cursor

Posted: Tue Aug 18, 2009 3:29 am
by bidgeeman
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

Posted: Tue Aug 18, 2009 8:57 am
by Klaus
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

Posted: Tue Aug 18, 2009 9:00 am
by bidgeeman
Oh...thank you very much Klaus for your help once again :)

Cheers
Bidge

Re: Follow Cursor

Posted: Tue Mar 03, 2020 12:58 pm
by kelyanok
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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 2:58 pm
by dunbarx
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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 3:16 pm
by dunbarx
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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 3:59 pm
by richmond62
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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 4:28 pm
by richmond62
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
-

Re: Follow Cursor

Posted: Tue Mar 03, 2020 4:37 pm
by dunbarx
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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 4:56 pm
by richmond62
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.

Re: Follow Cursor

Posted: Tue Mar 03, 2020 5:01 pm
by richmond62
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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 5:18 pm
by dunbarx
Richmond.

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

Craig

Re: Follow Cursor

Posted: Tue Mar 03, 2020 5:32 pm
by richmond62
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 8682 times

Re: Follow Cursor

Posted: Tue Mar 03, 2020 6:00 pm
by richmond62
I wonder what the point of

revStackNameIsIDEStack

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

Re: Follow Cursor

Posted: Tue Mar 03, 2020 6:23 pm
by richmond62
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