Chasing paths animation

I have a path that twists and turns around the screen.
I would like to have an image follow the path around the screen if it is known to be activated.
As far as I know, I can’t program an object to follow inside another object…But I know I can move it from one set point to another.
Am I correct in assuming that the best way I could create this effect would be as a product of many different animations in succession?

I don’t know what you mean by many different animations, but you could put something like this in a timer script to bind a position of one object to the position of another. You would have to add more code to make it do things like go around in a circle or something.

x=event.source.parent.getComponent('Button 1').getX()
y=event.source.parent.getComponent('Button 1').getY()
system.gui.moveComponent(event.source.parent.getComponent('Button'),x+100, y)

I you don’t have another component to follow, just use the time value or whatever to make it move by incrementing the x and y programatically.

code]
system.gui.moveComponent(event.source.parent.getComponent(‘Button’),event.source.value*5, y)
[/code]

I’m not sure that this is what you mean, but i used a little trick to animate objects on a conveyor.

I have an additional invisible path (created with the line tool) that i want to follow with the animated object. This line (named ‘Path’ in the example) has two custom properties, Path (dataset) and lastPoint (integer).

In the internalFrameOpened event, i extract the points from the path and write them to the dataset:

from java.lang import Double
import jarray

shapeComp = system.gui.getParentWindow(event).getComponentForPath('Root Container.Path')
shape=shapeComp.getShape()
pathIterator = shape.getPathIterator(None);
segment = jarray.zeros(6,'d')
path = []
# Iterate over all path segments
while not pathIterator.isDone():
	pathType=pathIterator.currentSegment(segment)
	print pathType
	if pathType==0 or pathType==1:
		path.append([segment[0], segment[1]])
	pathIterator.next()
print path
headers=['x','y']

# Set the custom property Path (has to be a dataset)
shapeComp.Path=system.dataset.toDataSet(headers, path)

The i use a timer to let another component (names ‘Circle’ here) follow the path from the dataset:

# Offsets from upper left -> center of the moving component
offsetX = 10
offsetY = 10

path = event.source.parent.getComponent('Path').Path
lastPoint = event.source.parent.getComponent('Path').lastPoint
if lastPoint < path.rowCount-1:
	lastPoint = lastPoint + 1
else:
	lastPoint = 0
event.source.parent.getComponent('Path').lastPoint = lastPoint
system.gui.moveComponent(event.source.parent.getComponent('Circle'), \
	int(path.getValueAt(lastPoint,'x'))-offsetX, int(path.getValueAt(lastPoint,'y'))-offsetY)

Depending on your layout it might be necessary to calculate the offsets to animated object’s center dynamically or recalculate the path dataset on window resize.

I like this solution, because it’s easy to add additional animation points or alter the animation path.

[quote=“chi”]I’m not sure that this is what you mean, but i used a little trick to animate objects on a conveyor.[/quote]That’s pretty cool :thumb_left:

very cool indeed. That was exactly what I was looking for. Thanks!