Follow Cursor
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Follow Cursor
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
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
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:
Best
Klaus
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
Klaus
Re: Follow Cursor
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!
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
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!

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
Hi.
LiveCode is SO much fun.
On a new card make a button. In the card script:
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
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
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
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
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
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
Of course that throws a "bluey" because until there are 10 lines in mouseTrack you
get a can't set object property notice.
-
get a can't set object property notice.
-
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
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.
-
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
Re: Follow Cursor
Richmond.
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
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.Of course that throws a "bluey" because until there are 10 lines in mouseTrack you
get a can't set object property notice.
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
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
Well this:
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.
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
previously, while what it needs to do is to move smoothly from its last location to the current mouse location.
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
I think I may have been guilty of "overthinking" the problem as this works:
-
Well, up to a point:
-
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:
-
- Attachments
-
- Monster2.livecode.zip
- Don't say you weren't warned.
- (16.07 KiB) Downloaded 211 times
Re: Follow Cursor
Richmond.
Monster 2 seems a bit, er, unsure of itself.
Craig
Monster 2 seems a bit, er, unsure of itself.

Craig
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
Aren't we all?Monster 2 seems a bit, er, unsure of itself.

The main problem as far as I can see is there is no (pseudoCode) on mouseNotMoving . . .
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
I wonder what the point of
revStackNameIsIDEStack
is, as when I dismiss that notice the script carries on functioning.
revStackNameIsIDEStack
is, as when I dismiss that notice the script carries on functioning.
-
- Livecode Opensource Backer
- Posts: 10097
- Joined: Fri Feb 19, 2010 10:17 am
Re: Follow Cursor
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