This site requires JavaScript, please enable it in your browser!
Greenfoot back
lehrerfreund
lehrerfreund wrote ...

2016/7/5

Animated GIFs in Greenfoot (3)

lehrerfreund lehrerfreund

2016/7/5

#
Hi, is it possible to use animated GIFs in Greenfoot? I found some threads here about a class GifImage, but I am not able to use it. Some say that you need an import for this class, but I don't know which one. Would aprreciate help very much, thanks! (I am using GF3, Stride-Scenarios, but I guess this should make no difference).
danpost danpost

2016/7/5

#
Maybe you are confused by the word 'import'. You do not need an 'import' statement. The 'GifImage' class comes with the greenfoot download. Just go to the menubar and select 'Edit>Import class...' and choose the GifImage class from the list in the pop-up. This will have the class added into your project.
lehrerfreund lehrerfreund

2016/7/9

#
danpost, thank you very much. This works. One question to this topic: As far as I can see it is only possible to change the animated frames in the rhythm of the act()-method (using the getCurrentImage()-method in the act()-method). When I turn down the speed of the scenario the animation also gets slower. I assume there is no way to use a fast running animation in a low-speed-scenario? Example of my code:
Super_Hippo Super_Hippo

2016/7/9

#
It is not possible to change an image more than once in an act-cycle and see the images without skipping images of the gif. What you could do for example is that you keep the speed but let the rest of the act-method only execute every second time or something.
danpost danpost

2016/7/9

#
You could create a GifImage object and use the 'getImages' method on it to load images to my Animation Support Class:
// instance field
private Animation animation;

// in constructor
animation = new Animation(this, new GifImage("animgif_beispiel.gif").getImages());
animation.setCycleActs(50); // acts to complete one cycle of images in animation

// in act
animation.run();
EDIT: nevermind ... I just realize that I had misunderstood what you were aiming for. Everything else needs to be slowed down in a faster running scenario (not the other way around). Maybe there is a still a way to make it work. Why exactly are you wanting to slow down the speed of the scenario? Usually, somewhere near the middle of the speed slider is a comfortable speed for most scenarios. Going faster will oftentimes create some lag and going slower will make keyboard input sluggish and awkward.
lehrerfreund lehrerfreund

2016/7/10

#
Thanks, Super_Hippo and danpost, for explaining this. I have no concrete plans; I just wondered if the speed of the GIF-animation has to go down according to the scenario-speed inevitably. I thought perhaps I am doing something wrong when animating the GIF in the rhythm of the act-method.
danpost danpost

2016/7/10

#
lehrerfreund wrote...
I just wondered if the speed of the GIF-animation has to go down according to the scenario-speed inevitably.
After taking a close look at the GifImage class (which I have not ever used myself), I have come to believe that the running speed of the animation is constant; it is the rate of updating the image of the animation due to the speed of the scenario that you are seeing.
Game/maniac Game/maniac

2016/7/11

#
Animated Gifs don't usually work in greenfoot applets.
danpost danpost

2016/7/11

#
Game/maniac wrote...
Animated Gifs don't usually work in greenfoot applets.
Please explain. I have tested it out and it seems to work just fine. Maybe a slight bit "sluggish" (with very slight hesitations in changing frames), but otherwise -- fine. There is also a "jump" when the scenario is started after being stopped. This is due to the use of System time in controlling the image changes. If this is bothersome and the images are not displayed for different amounts of time, you can use the images created from the GifImage class in my Animation class. The code given above is not quite accurate as a List object is returned from the GifImage class when 'getImages' is used, where an array of GreenfootImage obects is needed with the Animation class.
Game/maniac Game/maniac

2016/7/12

#
Weird, the last time I tried to use the GifImage class it didn't work when I uploaded it to the greenfoot site. Maybe they fixed it?
You need to login to post a reply.