Motion - Destination value

46 views
Skip to first unread message

Gustavo Mandolesi

unread,
Aug 11, 2013, 11:20:28 AM8/11/13
to codenameone...@googlegroups.com
Hello,

CN1 is such an amazing project. I´ve been playing with it for almost one month now, and I´m really enjoying it a lot.

Right now, I´m experimenting with the Motion class, trying to drive a very simple animation. I have a button that, when clicked, moves an object from the left edge of the display to the right one, horizontally, over the course of one second. If clicked again, the object should travel back to its origin, on the left.

I set up a Motion like this:

Motion.createLinearMotion(0, this.getWidth(), 1000);

Since the display width, in this case, is 320 pixels, it should go from 0 to 320 in one second.

In the paint()method of my object I get the current value of the motion using motion.getValue()to set its x variable, and, printing out the values, I got the following:

x=5
x=13
x=22
x=31
x=40
.
.
.
x=257
x=266
x=274
x=283

The last value set is 283, not 320

Thus, the animated object ends up in a different x coordinate than the one that was desired. I had to make a kind of a hack setting it up to the value of motion.getDestinationValue()when the motion is finished.

Then I have the reverse motion set to get the object back to the left:

Motion.createLinearMotion(this.getWidth(), 0, 1000);

This time, the last value set is 3, instead of zero.

My question is: am I missing something or this is not the expected behaviour for the Motion tweening interpolation? Shouldn´t that adjustment to the destination value be done by the Motion class itself?

Thanks in advance for your help, and keep up the good work!

Cheers,

\Gustavo

Shai Almog

unread,
Aug 11, 2013, 1:03:52 PM8/11/13
to codenameone...@googlegroups.com
Hi,
thanks Gustavo!

When isFinished() returns true you still have one more frame to draw, this is very confusing the first time around.

Gustavo Mandolesi

unread,
Aug 11, 2013, 7:18:45 PM8/11/13
to codenameone...@googlegroups.com
Ok, I got it.

Thank you!
> --
> You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/xrEHkrKQk40/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
> Visit this group at http://groups.google.com/group/codenameone-discussions.
> To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/9f37a0e9-b0b8-48a9-86de-65845f23f951%40googlegroups.com?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
Reply all
Reply to author
Forward
0 new messages