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

2022/12/12

some help

Carlos9173773838271 Carlos9173773838271

2022/12/12

#
I want a character to wait several seconds for some animations, something like this: setImage("Vegeta_42.png"); Greenfoot. delay(1); setImage("Vegeta_43.png"); Greenfoot. delay(1); setImage("Vegeta_44.png"); Greenfoot. delay(1); but with the delay it waits for the whole program and I want it to only wait for that object. some help
Jestry Jestry

2022/12/12

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Test class to simulate how a "gif" works.
 */
public class Test extends Actor
{
    private final String imageName = "Vegeta_";
    private int timeDurationToNextImage, currentIndex, counter;
    private int numberOfImages;
    
    // To work, you have to name your images right.
    // it goes through each image from 0 - (numberOfImages - 1)
    // hope it helps
    public void act() {
        if ( currentIndex < numberOfImages ) {
            // Like: setImage( "Vegeta_0.png" ); 
            setImage( imageName + currentIndex + ".png" );  
            if ( counter >= timeDurationToNextImage ) {
                counter = 0;
                currentIndex += 1;
            } else {
                counter += 1;
            }
        } else {
            currentIndex= 0;
        }     
    }
}
Carlos9173773838271 Carlos9173773838271

2022/12/12

#
the image changes very fast, Isn't there some code to make it wait a certain amount of time?
danpost danpost

2022/12/13

#
Carlos9173773838271 wrote...
the image changes very fast, Isn't there some code to make it wait a certain amount of time?
You need to set timeDurationToNextImage to some value like 8 so at line 8.
You need to login to post a reply.