Skip to main content

local variables and the Timeline element

8 replies [Last post]
kram
Offline
Joined: 2007-10-23
Points: 0

So far I have been looking around for some info and examples of using a Timeline object as a local variable of a Node such as:

<br />
               Circle {<br />
                    var radiusOfCircle = 5;<br />
                    var expandingRadiusTimeLine : Timeline = Timeline {<br />
                        repeatCount: Timeline.INDEFINITE<br />
                        keyFrames : [<br />
                            KeyFrame {<br />
                                time : 25ms,<br />
                                action: function() {<br />
                                    radiusOfCircle += 1;<br />
                                }<br />
                            }<br />
                        ]<br />
                    };</p>
<p>                    centerX: e.getX(),<br />
                    centerY: e.getY()<br />
                    radius: bind radiusOfCircle;<br />
                    fill: Color.BLACK<br />
                }<br />

This DOES compile, but I do not know how to start the timer. By putting:

expandingRadiusTimeLine.start(); I get compile errors... any thoughts?

P.S. how do I get nice JavaFX formatting on my code examples in the forums?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kram
Offline
Joined: 2007-10-23
Points: 0

As for the issue with the timeline, your example work great thanks Michael. I will consider that the solution to the thread

kram
Offline
Joined: 2007-10-23
Points: 0

Thanks for the help, but from looking at this is seems that the radiusOfCircle will forever be growing.

What I was actually after, was for each node to sort of have its own lifecycle, so that when I add a new circle to my list of objects, it will grow for one second, then get removed.

Im not at my PC with my app on it at the moment, so I cannot really give you what my compile error was, I honestly forget. But I had code like this:

[code]
Circle {
var radiusOfCircle = 5;
var expandingRadiusTimeLine : Timeline = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames : [
KeyFrame {
time : 25ms,
action: function() {
radiusOfCircle += 1;
}
}
]
}[b].start();[/b]

centerX: e.getX(),
centerY: e.getY()
radius: bind radiusOfCircle;
fill: Color.BLACK
}
[/code]

And I think the error was along the lines of "cannot place void command here" or something.

Thanks for the help!

alexsch
Offline
Joined: 2007-07-12
Points: 0

Just define the animation before the Circle creation:

[code]
var radiusOfCircle = 5;

var expandingRadiusTimeLine = Timeline {
repeatCount: 1
keyFrames : [
KeyFrame {
time : 25ms,
action: function() {
radiusOfCircle += 1;
}
}
]
}

expandingRadiusTimeLine.start();

Circle {

centerX: e.getX(),
centerY: e.getY()
radius: bind radiusOfCircle;
fill: Color.BLACK
}

[/code]

kram
Offline
Joined: 2007-10-23
Points: 0

Very sorry for the delayed reply...

Thanks for the help, but I really want each new circle instance to have its own timer.

The code you gave would create a new timer, which would increase the radius every 25ms, so when I create a new circle, the new circles would not start at a zeroed radius, but rather what ever the timer is up to.

Does this make sense?

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

I am not sure, if invoking a method right after an object literal is allowed at all. But the error message is confusing and does not help. Can you please file an issue in JIRA for that? http://openjfx.java.sun.com/jira

Now to your issue. I think, you should define a new class for that. Something like that:

[code]
class MyCircle extends Circle {
var expandingRadiusTimeLine : Timeline = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames : [
KeyFrame {
time : 25ms,
action: function() {
radius += 1;
}
}
]
};

init {
expandingRadiusTimeLine.start()
}
}
[/code]

This will create a new class, which is derived from Circle and adds a timeline-variable. Invoking start() in the init-function makes sure, that the timeline is started when the class is instantiated. (I omitted the local variable radiusOfCircle, because it was not necessary in this code example.)

You can use the class like you would a Circle. This will create an instance of MyCircle and start the timeline automatically.

[code]
MyCircle {
centerX: e.getX(),
centerY: e.getY()
radius: 5;
fill: Color.BLACK
}
[/code]

kram
Offline
Joined: 2007-10-23
Points: 0

Thanks Michael, I'll give that a try tonight went I can. As for the error message, I will get some more details and replcaition steps if I can, might not be a need to submit a JIRA issue on that just yet :)

alexsch
Offline
Joined: 2007-07-12
Points: 0

It is possible to define an animation in the beginning of a file and start it when any event occurs ( button pressed, mouse clicked and etc )

[code]
var radiusOfCircle = 5;

var expandingRadiusTimeLine : Timeline = Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames : [
KeyFrame {
time : 25ms,
action: function() {
radiusOfCircle += 1;
}
}
]
};

expandingRadiusTimeLine.start();

Frame {
title: "MyApplication"
width: 200
height: 200
closeAction: function() {
java.lang.System.exit( 0 );
}
visible: true

stage: Stage {
content: [Circle {
//centerX: e.getX(),
//centerY: e.getY()
radius: bind radiusOfCircle;
fill: Color.BLACK
}]
}
}

[/code]

I use [ code ] [ /code ] tags for a code formatting.

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

What compile-errors do you get?