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

2020/3/15

How can I horizontally flip a gif?

CieloMungcal CieloMungcal

2020/3/15

#
I am trying to flip my actor horizontally when it turns left, but it keeps facing left and right repeatedly everytime it goes left. import greenfoot.*; public class mario extends Actor { GifImage myGif = new GifImage("mariowalk.gif"); GifImage myGif2 = new GifImage("mariowalk2.gif"); public void act() { actions(); } public mario() { GreenfootImage image = getImage(); image.scale(image.getWidth() - 50, image.getHeight() - 100); setImage(image); for (GreenfootImage image2 : myGif2.getImages()) { int wide = image2.getWidth() - 100; int high = image2.getHeight() -100; image2.scale(wide, high); } for (GreenfootImage image1 : myGif.getImages()) { int wide = image1.getWidth() - 100; int high = image1.getHeight() -100; image1.scale(wide, high); } } public void actions() { if(Greenfoot.isKeyDown("left")) { move(-4); setImage(myGif2.getCurrentImage()); getImage().mirrorHorizontally(); } if(Greenfoot.isKeyDown("right")) { move(4); setImage(myGif.getCurrentImage()); } } }
danpost danpost

2020/3/15

#
You either need two complete set of images (two GifImage objects) or you need to track the flipping of the one set. If tracking, you should flip all images at once to keep them all consistent with each other.
CieloMungcal CieloMungcal

2020/3/15

#
thanks! i made two complete set of images
You need to login to post a reply.