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
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