glegris / pulpcore

Automatically exported from code.google.com/p/pulpcore
0 stars 1 forks source link

TimeLine.moveTo takes sprite's base properties #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create the following basic program:
Sprite nb = new FilledSprite(100,100,20,20,YELLOW);
Timeline tl = new Timeline();
tl.moveTo(nb, 200, 300, 1000);
tl.after(1).moveTo(nb, 0, 0, 1000);
addTimeline(tl);
2. Run the program

I expect to see the sprite moving from its initial location (100,100) to
the second location (200,300) and from the second location (200,300) to the
third location (0,0).

What I see instead is, the sprite moving from (100,100) to (200,300), then
it disapears and appears immediately at its initial location. Finally, I it
moves from the initial location (200,300) to the third location (0,0).

Somehow moveTo doesn't update the properties inside the sprite after it has
finished animating it. Then, when another moveTo occurs, it uses the
initial location properties, instead of the new ones, (which were supposed
to be setted by moveTo when it is done animating it).

The same happens for scaleTo.

Even setting the properties directly with a TimeLineEvent won't solve this
problem, that is:

      tl.moveTo(nb, 200, 300, 1000);
      tl.after().add(new TimelineEvent(1) {
        public void run() {
            // TODO Auto-generated method stub
            nb.x.set(200);
            nb.y.set(300);
        }

      });
      tl.after(210).moveTo(nb, 313, 313, 2000);

Tried it on the latest pulpcore (0.11.5) on Windows vista, with the
following javas:
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
Eclipse SDK
Version: 3.4.2
Build id: M20090211-1700

(not that I think it is related).

Original issue reported on code.google.com by elaz...@gmail.com on 15 Jul 2009 at 7:54

GoogleCodeExporter commented 9 years ago
The problem is simple. The Tween class takes the properties of the sprite by 
value,
and not by reference. that is the code:

        int fFromValue = property.getAsFixed();
        int fToValue = CoreMath.toFixed(toValue);
        add(property, new Tween(fFromValue, fToValue, duration));

should be

        int fToValue = CoreMath.toFixed(toValue);
        add(property, new Tween(property.getAsFixed(), fToValue, duration));

And of course Tween object should be changed accordingly. Is there a reason not 
to do
it, a reason I might be missing?

Original comment by elaz...@gmail.com on 15 Jul 2009 at 8:04

GoogleCodeExporter commented 9 years ago
All relative animation commands (moveTo, animateTo, etc) get the start value 
from the moment the animation is 
defined, rather than from the moment the animation runs. Changing this behavior 
might not be trivial in some 
cases, but it will be considered.

For a workaround, use the move() command instead of moveTo()

Original comment by brack...@gmail.com on 15 Jul 2009 at 4:33

GoogleCodeExporter commented 9 years ago
Here's a patch. I check whether or not the animation has started using the
`getSection()` method. I cache the previous section, and when the section 
changes I
load the values.

Original comment by elaz...@gmail.com on 19 Jul 2009 at 6:40

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the patch. I didn't use the exact code because it didn't include Int 
or Color properties, or include unit 
tests. But the fix is based off of the patch.

Original comment by brack...@gmail.com on 3 Aug 2009 at 3:54