Go Back   OpenLaszlo Developers Forums > Non-programming help and discussions > Development Tools and Practices

Development Tools and Practices Questions about development tools and practices. An appropriate place to talk about text editors, IDEs, and anything else that makes your development life easier.

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-23-2003, 03:58 PM
antun antun is offline
Forum Administrator
 
Join Date: Jun 2002
Location: San Francisco
Posts: 1,678
antun is on a distinguished road
Animating to and from a location

Here is a handy pattern for animating an object to a specific location/size, and then returning it to its original position/size without having to do a lot of attribute management. Basically, the object caches its present coordinates and dimensions when the beginning animation starts, and then animates the object back to the cached values when the finish animation runs.

Using this pattern, you can guarantee that am object is in a consistent state in order to perform some UI presentation without worrying about where it was or what it looked like. When finished, the object will automatically return to its previous state. For example, move the smiley to the first location using the button, then drag him around using the mouse. When you're ready to send him back to where he started, all you need do is click the second button.

Ignore the compilation warnings for the time being.

Code:
<canvas>
    <view id="myThing" resource="smiley.png" 
          onmousedown="this.dragger.apply()"
          onmouseup="this.dragger.remove()">
        <dragstate name="dragger" />

        <attribute name="oldX" value="0" type="number" />
        <attribute name="oldY" value="0" type="number" />
        <attribute name="oldWidth" value="0" type="number" />
        <attribute name="oldHeight" value="0" type="number" />

        <animatorgroup name="animateToSpecificPlace" process="simultaneous" 
                       start="false">
            <animator attribute="x" to="200" duration="1000" />
            <animator attribute="y" to="50" duration="1000" />
            <method event="onstart">
                this.parent.setAttribute( "oldX", myThing.x );
                this.parent.setAttribute( "oldY", myThing.y );
            </method>
        </animatorgroup>

        <animatorgroup name="returnToStartingState" process="simultaneous" 
                       start="false" >
            <animator attribute="x" 
                      to="${this.parent.parent.oldX}" duration="1000" />
            <animator attribute="y" 
                      to="${this.parent.parent.oldY}" duration="1000" />
        </animatorgroup>
    </view>

    <view name="controls">
        <simplelayout axis="x" spacing="2" />
        <button onclick="myThing.animateToSpecificPlace.start()">
            Go to first place
        </button>
        <button onclick="myThing.returnToStartingState.start()">
            Go back to where you started
        </button>
    </view>
</canvas>
Enjoy!

Thanks to Iconfactory (http://www.iconfactory.com/) for the images.
Attached Images
File Type: png smiley.png (4.4 KB, 675 views)
__________________
http://www.antunkarlovac.com/blog/

Try out Webtop today:
http://www.gowebtop.com/
Reply With Quote
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:18 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.