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

2017/12/3

Image Switch frequency

Pjagadish Pjagadish

2017/12/3

#
Hi, I am creating a game for school and I was wondering if there was a way to change the frequency of image switching. Meaning that the image will switch faster sometimes and faster other times. Thanks for the help!
EduandErnst EduandErnst

2017/12/3

#
Hi there, you could use a simple switch case statement to implement an animation with In your field import your pics like:
public static final GreenfootImage boyWalkright1 = new GreenfootImage("boymovingright1.png");
Then write a method like.. In this case I pressed a key and called this method then my frame was incremented by one ... This way you can very easily control your image switching by changing the value of your case
public void WalkRight(){
        frame++; 
        switch (frame){
            case 1: setImage(boyWalkright1); break;
            case 4: setImage(boyWalkright2); break;
            case 7: setImage(boyWalkright3); break;
            case 9: setImage(boyWalkright4); break;

            case 11: frame = 0; break;
        }
    }

Pjagadish Pjagadish

2017/12/3

#
That's pretty cool. Thanks!
You need to login to post a reply.