PDA

View Full Version : Synchronize Timers


loken
02-02-2009, 03:52 PM
Hi,

I was wondering if it would be possible to synchronize timers. I am working on animation similar to the ipod wherein when I roll up or down the pictures would change dynamically depending on the motion of the mouse with the middle picture enlarged. While mousedown, I would then roll the pictures with a delay of 50 so I can respond to the mousedown event rapidly. Then I call a method which checks the mouse position and depending on the results I would call either rollup or rolldown method. I then display on the debugger the mouse motion and the coordinates. That works great, problem is the rolled pictures moves too fast.

In short, the app should respond to the mousedown quickly regardless of changes in direction (up or down) and animate the pictures accordingly with the direction the mouse is rolling but slower than the intended response. Here's how my code looks like


<method name="rollup">
//do some animation
</method>
<method name="rolldown">
//reverse rollup animation
</method>

<view id="mainInterface" clickable="true">
<attribute name="isLMBDown" type="boolean"/>
<attribute name="diffQ" type="number"/>
<attribute name="initY" type="number"/>

<handler name="onmouseover">
<![CDATA[
if(canvas.getMouse("y") >= 44 && canvas.getMouse("y") <= 624){
this.initY=canvas.getMouse("y");
}
]]>
</handler>

<handler name="onmousedown">
this.onmousedown.sendEvent();
</handler>

<handler name="onmousedown">
this.isLMBdown = true;
this.move();
</handler>

<handler name="onmouseup">
this.isLMBDown = false;
this.initY=canvas.getMouse("y");
LzTimer.removeTimer( this.lmbDown );
</handler>
<method name="setTimer">
this.lmbDown = new LzDelegate( this, "move" );
LzTimer.addTimer( this.lmbDown,50 );
</method>
<method name="move">
<![CDATA[
Debug.write("init y position: ",this.initY);
Debug.write("Current y position: ",canvas.getMouse("y"));
if(this.initY > canvas.getMouse("y")){
this.diffQ=(((canvas.getMouse("y")-this.initY))%10)/-1;
Debug.write("roll up: ",this.diffQ);
//rollup();
LzTimer.addTimer( new LzDelegate( this, "rollup" ), 500 );
}
if(this.initY < canvas.getMouse("y")){
this.diffQ=((canvas.getMouse("y")-this.initY))%-10;
Debug.write("roll down: ",this.diffQ);
//rolldown();
LzTimer.addTimer( new LzDelegate( this, "rolldown" ), 500 );
}
if (this.isLMBDown) {
this.setTimer();
}
]]>
</method>
<!--
more subviews
-->
</view>



It's a bit of a mess...Can anyone tell where I'd gone wrong, and what I should do? How can I allow a delay between timers.
I was also wondering how I could start and stop the animation dynamically depending on the number of pixels the mouse is moved or is that not possible.
Sorry for my english.

Any advice would gladly be appreciated.

Loken

loken
04-16-2009, 10:30 PM
I am really a bit disappointed, I have waited but still no response. However I do not intend to give up. I am currently working on a workaround for myself and hope to find a solution soon.

mjessup
04-20-2009, 04:32 AM
Hi Loken, If I am reading you statements/questions correctly it sounds like you are reacting to the mouse movement the way you want, you just want to have "smoother" animation. If thats the case I would say a solution may be that you use an animator (either scripted, or alter a declared animator via script): Something along the lines of:


... code for view and handling mouse drag ...
<method name="actionmethod">
//stop the animator if it is still running
mainAnimator.stop();

//probably some current measure of the attribute (i.e. x coordinate of a view)
mainAnimator.anim1.setAttribute('from', ???);
//whereever the view needs to end up
mainAnimator.anim1.setAttribute('to', ???);

//maybe alter the duration depending how far you have to move
mainAnimator.anim1.setAttribute('duration', ???);

... adjust some other sub-animator attributes for the mouse movement

mainAnimator.doStart();
</method>
<animatorgroup name="mainAnimator">
<animator name="anim1" from="???" to="???" ... />
...
</animatorgroup>
</animator>

I apologize for the vagueness of my code, but I wasn't entirely sure how you were going about the process of animating your views currently. I think generally this is what you need, dynamically updating your view animators and then starting them (and stopping them first if they are running.) Let me know if I am off in interpreting your question or my explanations above are unclear.

loken
04-20-2009, 04:24 PM
Thank you mjessup!

I was glad somebody actually shed some light on the topic. Actually I use two custom libraries. One handles all the animation and the other one performs the monitoring of the mouse movements. I have set global variables that contains the status of the mouse (direction, motion, etc.) and I think I missed out on checking the status of the animation.

I will have a look at your code. I'll take your advice and post you with any updates.

Thank you!