Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
hliljegren
- Posts: 108
- Joined: Sun Aug 23, 2009 7:48 am
-
Contact:
Post
by hliljegren » Thu May 20, 2010 3:15 pm
I'm trying to simulate the Mac OS X behavior with windows changing size via animation. But the animations are way to slow
To get it working somewhat I lower the iterations to 10 which makes a compromise between speed and fluidity. Anyone know of a better way? When I resize a stack via the mouse it's instant and fluid if I set the
liveResizing to true!
When timing my window it takes ~150 ms to go from big to small and ~320 ms from small to big.
Here's the code:
Code: Select all
on animateResize endWidth, endHeight
put the width of this stack into startWidth
put the height of this stack into startHeight
put (endWidth - startWidth) / 10 into widthStep
put (endHeight - startHeight) / 10 into heightStep
put the top of this stack into myTop
put the left of this stack into myLeft
lock messages
repeat with i = 1 to 10
add widthStep to startWidth
add heightStep to startHeight
lock screen
set the width of this stack to startWidth
set the height of this stack to startHeight
set the top of this stack to myTop
set the left of this stack to myLeft
unlock screen
end repeat
unlock messages
// Ensure that the size is correct
lock screen
set the width of this stack to endWidth
set the height of this stack to endHeight
unlock screen
end animateResize
___________________________________
MacBook Pro, 15" 2.6GHz i7 Mac OS X 10.10.4
iMac 27", 3.2 GHz Quad i7, Mac OS 10.10.4
LiveCode 7.0.6 or 8.0dp4
-
Mark
- Livecode Opensource Backer
- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Thu May 20, 2010 5:58 pm
Hi hliljegren,
You will get much better results if you set the rect of the stack at once, instead of the widith, height, top and left separately. You don't need to lock messages or the screen. Locking the screen slows down the process. If you have a resize handler that you don't want to run while this script is running, then add a custom property or global variable somewhere and check it at the start of the resize handler. Repeat with messages and an additional wait 0 millisecs with messages at the end of the repeat loop will also help.
Best regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
hliljegren
- Posts: 108
- Joined: Sun Aug 23, 2009 7:48 am
-
Contact:
Post
by hliljegren » Thu May 20, 2010 9:23 pm
Thanks for the reply but I must say NO it doesn't. I've already tried that. I was actually my first implementation and my second was to use the loc instead of left and top, but both where slower...
Setting the rect gives me almost the same time when going from smaller to bigger but almost the double time when going from bigger to smaller. I get around 320 milliseconds in both directions. If I don't have the lock messages I get the same effect (same time small->big but double time big-small). Maybe it's more correct to say that when adding the lock messages I cut the time in half when shrinking the window, as in all other versions I get almost the same time in both directions.
When setting width and height (and top and left) separately I of course need the lock screen.
Maybe this is a good challenge for everyone to try to improve the speed of the code...
___________________________________
MacBook Pro, 15" 2.6GHz i7 Mac OS X 10.10.4
iMac 27", 3.2 GHz Quad i7, Mac OS 10.10.4
LiveCode 7.0.6 or 8.0dp4
-
bn
- VIP Livecode Opensource Backer
- Posts: 4036
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Fri Jun 04, 2010 12:24 pm
Hi Hliljegren,
I did try to get a smoother animation but did not succeed.
Today I found in a discussion on the list
revChangeWindowSize
It is a lot smoother then changing the rect of the stack.
make a small stack and put a button in it: Script of the button
Code: Select all
on mouseUp
put the width of card 1 into myWidth
put the height of card 1 into myHeight
revChangeWindowSize 600,600
wait 1 second
revChangeWindowSize myWidth, myHeight
end mouseUp
look it up in the dictionary, there are more options to this command.
regards
Bernd