Stop-Start: animation along a path
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Stop-Start: animation along a path
So: I have a silly stack with a button that has an icon of a sunburst
that goes round a circular path (generated using the old (sin x), (cos x) trick).
Animation is initiated by another button containing this script:
on mouseUp
move btn "sun" to the points of grc "path1" in 20 seconds
end mouseUp
Now the sunburst button contains a script:
on mouseEnter
stop moving btn "sun"
end mouseEnter
nothing either special or remarkable there!
Now when my pointer enters the button "sun" the animation stops as it should.
The button stops where it is at that moment.
So, what's Richmond's problem?
Well, apart from the well-known psychological ones . . .
it is that I should like, somehow, to have a mouseUp script (either in the "sun" button, or elsewhere)
that would reinitiate animation along a path at the point where it stopped.
that goes round a circular path (generated using the old (sin x), (cos x) trick).
Animation is initiated by another button containing this script:
on mouseUp
move btn "sun" to the points of grc "path1" in 20 seconds
end mouseUp
Now the sunburst button contains a script:
on mouseEnter
stop moving btn "sun"
end mouseEnter
nothing either special or remarkable there!
Now when my pointer enters the button "sun" the animation stops as it should.
The button stops where it is at that moment.
So, what's Richmond's problem?
Well, apart from the well-known psychological ones . . .
it is that I should like, somehow, to have a mouseUp script (either in the "sun" button, or elsewhere)
that would reinitiate animation along a path at the point where it stopped.
- Attachments
-
- Stop_Start.livecode.zip
- Here's my stack.
- (66.07 KiB) Downloaded 226 times
Re: Stop-Start: animation along a path
Hi,
Did a quick one. ( LC 8 )
Please, do test it!
And yes, there is lots of room for improvment...
HTH,
Thierry
Did a quick one. ( LC 8 )
Please, do test it!
And yes, there is lots of room for improvment...
HTH,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Stop-Start: animation along a path
The move message:
- executes only once
- can not be interrupted and continued
The way I would do it would be to create a "game loop" that moves the sun to the next point, then sends itself a message (to move again) in "x" millisecs. When it hits the last point, start again at the top. This will keep the sun moving continuously. You can adjust the speed by changing "x". (another twist to it)
Also include in that loop a check for a flag (true/false) If true, then move the sun and send the next message. If false, do nothing (the sun stops moving). To start it up again just reissue the game loop command
Make sure to declare the flag global, so that you can start/stop the sun from anywhere. If you put the points of grc "path 1" into a variable and cycle through those to move the sun, make the line count variable global. When the sun starts up again, it will continue from where stopped.
Does this make sense? I can give you the code if I did not explain it well enough. In LiveCode, the code is sometimes easier to read then the verbal explanation
- executes only once
- can not be interrupted and continued
The way I would do it would be to create a "game loop" that moves the sun to the next point, then sends itself a message (to move again) in "x" millisecs. When it hits the last point, start again at the top. This will keep the sun moving continuously. You can adjust the speed by changing "x". (another twist to it)
Also include in that loop a check for a flag (true/false) If true, then move the sun and send the next message. If false, do nothing (the sun stops moving). To start it up again just reissue the game loop command
Make sure to declare the flag global, so that you can start/stop the sun from anywhere. If you put the points of grc "path 1" into a variable and cycle through those to move the sun, make the line count variable global. When the sun starts up again, it will continue from where stopped.
Does this make sense? I can give you the code if I did not explain it well enough. In LiveCode, the code is sometimes easier to read then the verbal explanation
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: Stop-Start: animation along a path
and you can add this line before the 'end repeat'
if distance is 0 then exit repeat
Best,
Thierry
if distance is 0 then exit repeat
Best,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Stop-Start: animation along a path
Here is the code I referred to:
This is the "game loop"
This is the code to set it up:
This is the code to start it:
This is the code to stop it:
This is the "game loop"
Code: Select all
global thePoints,theFlag,theLineNum
command movesun
if theFlag then
set the loc of btn "sun" to line theLineNum of thePoints
add 1 to theLineNum
if theLineNum > ( the number of lines of thePoints) then
put 1 into theLineNum
end if
send movesun to me in 10 millisecs
end if
end movesun
Code: Select all
global thePoints,theFlag,theLineNum
on openCard
put the points of grc "path 1" into thePoints
put 1 into theLineNum
end mouseUp
Code: Select all
global thePoints,theFlag,theLineNum
on mouseUp
put true into theFlag
movesun
end mouseUp
Code: Select all
global theFlag
on mouseEnter
put false into theFlag
end mouseEnter
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stop-Start: animation along a path
I am trying to stop my btn "sun" moving in a different way and wonder why I am getting
an error message:
message id is not an integer
with this script in my button:
on mouseDown
put the loc of me into fld "SHAMS"
put the pendingmessages into myMsg
repeat for each line myMsg in myMsgs
cancel item 1 of myMsg
end repeat
end mouseDown
an error message:
message id is not an integer
with this script in my button:
on mouseDown
put the loc of me into fld "SHAMS"
put the pendingmessages into myMsg
repeat for each line myMsg in myMsgs
cancel item 1 of myMsg
end repeat
end mouseDown
Re: Stop-Start: animation along a path
Shouldn't
be
Code: Select all
put the pendingmessages into myMsg
Code: Select all
put the pendingmessages into myMsgs
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stop-Start: animation along a path
I'm a steaming idiot who delights in over-complicating things . . .
So: I have my button "sun" using a points list, and ALL I now
have in my button "sun" is the ultimate short script:
on mouseEnter
exit to top
end mouseEnter
AND . . . it works!
So: I have my button "sun" using a points list, and ALL I now
have in my button "sun" is the ultimate short script:
on mouseEnter
exit to top
end mouseEnter
AND . . . it works!
- Attachments
-
- Stop_Start_R2.livecode.zip
- Here's the stack.
- (68.33 KiB) Downloaded 248 times
Re: Stop-Start: animation along a path
I am completely puzzled that "exit to top" will really exit your repeat loop in another script! 

-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stop-Start: animation along a path
What that shows us, Klaus, is that although it is extremely obvious that
I have a lot more to learn about Livecode after about 15 years,
you've got a bit too . . .
Frankly, it makes Livecode look like a bottomless pit.
Hey; but it's fun climbing down into the pit!
I have a lot more to learn about Livecode after about 15 years,
you've got a bit too . . .
Frankly, it makes Livecode look like a bottomless pit.
Hey; but it's fun climbing down into the pit!
Last edited by richmond62 on Wed Jun 29, 2016 7:18 pm, edited 1 time in total.
Re: Stop-Start: animation along a path
Come on, name it, don't be shy!richmond62 wrote:What that show us, Klaus, is that although it is extremely obvious that
I have a lot more to learn about Livecode after about 15 years,
you've got a bit too . . .

-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stop-Start: animation along a path
It seemeth that exit to top worketh universally, insofar as it stoppeth
all handlers.
I have a feeling that the last time I used exit was in PASCAL in about 1985 . . . bottomless pit indeed.
The 7.1.4 Dictionary is a bit vague about some aspects of exit,
but what does become clear is that if one wants to send an exit command
from outwith the script one wants to stop the only one that will work is
exit to top, for I cannot for the life of me see how one could send
exit mouseUp from one control to another.
all handlers.
I have a feeling that the last time I used exit was in PASCAL in about 1985 . . . bottomless pit indeed.
The 7.1.4 Dictionary is a bit vague about some aspects of exit,
but what does become clear is that if one wants to send an exit command
from outwith the script one wants to stop the only one that will work is
exit to top, for I cannot for the life of me see how one could send
exit mouseUp from one control to another.
-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stop-Start: animation along a path
To be honest the
move img "XXX" to the points of grc "ZZZ"
is a rather silly thing as to control anything within that
action is well nigh impossible.
Both in this discussion and elsewhere I have found that the easiest way to get round
this limitation is to draw a vector path and then put its points into a listField:
put the points of grc "pathway" into fld "pathPoints"
and then, as it is largely unneeded, delete the vector path.
It is then comparatively easy to mess around with the points in the listField
in all sorts of entertaining ways.
move img "XXX" to the points of grc "ZZZ"
is a rather silly thing as to control anything within that
action is well nigh impossible.
Both in this discussion and elsewhere I have found that the easiest way to get round
this limitation is to draw a vector path and then put its points into a listField:
put the points of grc "pathway" into fld "pathPoints"
and then, as it is largely unneeded, delete the vector path.
It is then comparatively easy to mess around with the points in the listField
in all sorts of entertaining ways.
Re: Stop-Start: animation along a path
It's a very easy task, if you know how to do it. Here is the correct simple code of the start/stop button, you don't need the circle graph:
########CODE#######
on mouseUp
if the label of me is "GO" then
set the label of me to "STOP"
else
set the label of me to "GO"
end if
moveSun
end mouseUp
on moveSun
if the label of me is "STOP" then
put the angolo of me into temp
put 300 + (201 * sin(temp)) into yy
put 300 + (201 * cos(temp)) into xx
set the loc of button "Sun" to xx,yy
add 0.1 to temp
if temp > (2 * pi) then
put 0 into temp
end if
set the angolo of me to temp
send "movesun" to me in 0.01 sec
end if
end moveSun
#####END OF CODE#####
########CODE#######
on mouseUp
if the label of me is "GO" then
set the label of me to "STOP"
else
set the label of me to "GO"
end if
moveSun
end mouseUp
on moveSun
if the label of me is "STOP" then
put the angolo of me into temp
put 300 + (201 * sin(temp)) into yy
put 300 + (201 * cos(temp)) into xx
set the loc of button "Sun" to xx,yy
add 0.1 to temp
if temp > (2 * pi) then
put 0 into temp
end if
set the angolo of me to temp
send "movesun" to me in 0.01 sec
end if
end moveSun
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- Livecode Opensource Backer
- Posts: 10090
- Joined: Fri Feb 19, 2010 10:17 am
Re: Stop-Start: animation along a path
Well, what you're doing with your code is great,It's a very easy task
BUT it is NOT controlling an object running along a series of points of a vector image
as in:
move img "HHH" to the points of grc "MyPath"
Also, while that works for a circular path, because you use a sine formula to generate points on a circle
(and guess how I made that circular path in the first place), it won't be much good with something like this:
At which point you will probably have to revert to "my" way of bunging the points into a listField.