animating gifs across the screen

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Coffee1633
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 219
Joined: Mon Dec 05, 2011 5:35 pm
Location: Kanagawa, Japan

animating gifs across the screen

Post by Coffee1633 » Sun Jan 25, 2015 2:11 am

I am animating an 8 frame gif across the screen ( a bird ) and as time goes on the animation gets jerky.
Everything works but it doesn't seem optimized. Here is the situation.

1) not using a game loop or equivalent. just using send in time
2) the birds wings flap using an animated gif with 8 frames set to 100 ms cycle (in photoshop) and imported directly into an image ( not a button)
3) set the repeatCount of img "bird" to -1
4) set the layermode of img "bird" to "dynamic" --accelerated rendering is set to TRUE on the PreOpenStack handler

Code: Select all

--code to have it cycle back to the left side of screen after leave right side deleted for brevity
set the loc of img "bird" to the loc of image "bird" + kMOVE_DISTANCE  --4 pixels
send "UpdateBirdAnimation" to me in kMOVE_SPEED millisecs  --40 ms
after 5-6 cycles across the screen the bird animation starts to get jerky.

What am I missing here?
1) should the bird gif be in a button instead? If so, what is wrong with using a gif animation?
2) or should I not use a gif at all and manually cycle through the sprites instead? (that's a pain)
3) Is there something else that I am missing?

lastly, the project browser is closed when I run the animation in the IDE, so that's not it
does anyone have any insight into this issue?

coffee

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: animating gifs across the screen

Post by Newbie4 » Sun Jan 25, 2015 6:31 am

It sounds like you have a good handle on what you are doing.

My suggestion is to add a button and set it's icon to the ID of your animated gif. Then move the button instead. That should make it move smoother. We have had no problems with animated gifs using that approach.

If you still see problems with it slowing down in time, there may be a different cause for it (like too many messages being queued up, timing issues or a number of other possible reasons.) We would have to see more of your code to look for causes and improvements.

Thanks for the post
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: animating gifs across the screen

Post by Klaus » Sun Jan 25, 2015 11:01 am

Hi Coffee,

I really wonder, why this line doesn't throw an error:
...
set the loc of img "bird" to the loc of image "bird" + kMOVE_DISTANCE --4 pixels
...
The LOCATION of an object is a pair of 2 coordinates -> 100,258
So what does -> + kMOVE_DISTANCE do, I mean WHERE will this be added?
Remember, we have 2 (TWO) values here in the loc!


Best

Klaus

Coffee1633
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 219
Joined: Mon Dec 05, 2011 5:35 pm
Location: Kanagawa, Japan

Re: animating gifs across the screen

Post by Coffee1633 » Sun Jan 25, 2015 4:12 pm

Hi Klaus

Code: Select all

I really wonder, why this line doesn't throw an error:
...
set the loc of img "bird" to the loc of image "bird" + kMOVE_DISTANCE --4 pixels
I was recreating the code off the top of my head. You're right it would throw an error

It should be

Code: Select all

set the right of img "bird" to the right of img "bird" + kMOVE_DISTANCE --4 pixels
:oops:

thanks Newbie4
I'll put the gif in a button and try that.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: animating gifs across the screen

Post by Klaus » Sun Jan 25, 2015 6:38 pm

Hi,

OK, just wanted to be sure! :D
And yes, using images as ICONS in buttons is the way to go!


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”