Page 1 of 1
move "to the points of" a graphic BACKWARDS
Posted: Wed Aug 05, 2009 11:53 pm
by acidjazz
Is there a simple way to get a graphic (e.g., rectangle) to move "to the points" of another graphic (e.g., a line) in the OPPOSITE direction? Here's the basic code:
Code: Select all
move graphic "box" to the points of graphic "line" in 1 seconds
Just like you can make a repeat loop go backwards (100
down to 0), is there a way to modify this code? I know I can overlay a second and identical "line" graphic, created by clicking on the
end point first, and then dragging to the
start point, but that seems very clumsy.
Thanks!
Mark
Posted: Thu Aug 06, 2009 3:00 am
by shadowslash
Only possible reason I can think of is that you should re-arrange the points of the line graphic. (E.g. Put the last set of points to the topmost part of the points then the next last set of points to the second line and so on...)
Posted: Thu Aug 06, 2009 5:27 am
by acidjazz
Okay, I think I've got it. I put all the points into a list called "tPointList" and then using a repeat loop I move to each point (i.e., each line in tPointList). To go backwards I just read the list starting at the last line of the tPointList and work my way down to line 1.
Code: Select all
on mouseUp
put the points of graphic "path" into tPointList
set the MoveSpeed to 500
-- MOVE FORWARD
repeat with i = 1 to the number of lines of tPointList
move graphic "spaceship" to line i of tPointList
end repeat
-- MOVE BACKWARD
repeat with i = the number of lines of tPointList down to 1
move graphic "spaceship" to line i of tPointList
end repeat
end mouseup
This will move an object along the points of a graphic (forwards, and then backwards) no matter how many points it has (e.g., line, rectangle, freehand polygon). Increase the MoveSpeed property to make it go faster.
I still think it's a shame you can't just say
Code: Select all
Move to the points of graphic "path" descending
Cheers,
Mark
Posted: Thu Aug 06, 2009 10:27 am
by bn
Mark,
you could reverse the points of the graphic like in:
Code: Select all
on mouseUp
put the points of graphic 1 into tpointList
repeat with i = the number of lines of tpointList down to 1
put line i of tpointList & cr after tReversePoints
end repeat
delete last char of tReversePoints -- a return
set the points of graphic 1 to tReversePoints
end mouseUp
then you can just let the graphic move along the points of graphic "line".
You can do it either on the fly, it is fast and one does not notice the reversal of the points, or you can create a script local variable for forward and backward movement and just set the points of graphic "line" to the appropriate variable. It is still not the "move backwards" command but it may be easier to code.
regards
Bernd
Posted: Thu Aug 06, 2009 1:21 pm
by bn
Mark,
try:
Code: Select all
on mouseUp
ReversePoints
move graphic "box" to the points of graphic "line" in 1 seconds
end mouseUp
on ReversePoints
put the points of graphic "line" into tpointList
repeat with i = the number of lines of tpointList down to 1
put line i of tpointList & cr after tReversePoints
end repeat
delete last char of tReversePoints -- a return
set the points of graphic "line" to tReversePoints
end ReversePoints
regards
Bernd
Posted: Thu Aug 06, 2009 5:05 pm
by acidjazz
Thanks Bernd! It's amazing how much I learn from asking a question, then proceding to spend 2 additional hours trying to answer that question myself, and then getting feedback. If I hadn't spent the time, I probably wouldn't have understood your code, but now that I did, I think using a simple "ReversePoints" handler is the way to go. Gracias.
- Mark