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

2017/10/7

Is there a way to check if the actors image is flipped or not?

Beamo Beamo

2017/10/7

#
Hi again! My query is about whether or not you can check if the actors image is looking left, or looking right (in a sense). The code I'm using to flip the actors image is this:
GreenfootImage img = getImage();
img.mirrorVertically();
setImage(img);
But if I use this in the move() method, I could be pressing the right button and it would flip the image every time that I press it. So again, my question is about whether or not you can check what direction the image is facing. Any help would be appreciated! Thanks!
Beamo Beamo

2017/10/7

#
If you cannot, do you think I should just copy the image file and rotate it?
Super_Hippo Super_Hippo

2017/10/7

#
You could compare the image to the original image to see if it is the same (not flipped) or not (flipped). However, you can also save a reference to both versions and use them as different images.
private GreenfootImage imageRight, imageLeft;

//in constructor
imageRight = new GreenfootImage("filename.png");
imageLeft = new GreenfootImage("filename.png");
imageLeft.mirrorHorizontally();
Beamo Beamo

2017/10/7

#
Ah I see! That'd work quite well actually. Thanks again!
Beamo Beamo

2017/10/7

#
Oh there is something I forgot to mention, sorry! I have already created the images for the game, so would I still use "new GreenfootImage("")"?
Super_Hippo Super_Hippo

2017/10/7

#
You mean you set the image with a right click on the class? Then you can still do it like this or use 'getImage()' instead.
Beamo Beamo

2017/10/7

#
Ah right, thank you again!
Beamo Beamo

2017/10/7

#
Hi! Sorry I just tested the scenario and when I place the actor in the world I get the following error: java.lang.IllegalArgumentException: Filename 'idle1.png' has the wrong case. It should be: 'Idle1.png' I ended up setting the actors image to unspecified as it made things less complicated, and this is the code in the constructor now:
public Hero(){
        //setting Images
            //idle1
        GreenfootImage idleOneRight = new GreenfootImage("idle1.png");
        GreenfootImage idleOneLeft = new GreenfootImage("idle1.png");
        idleOneRight.mirrorHorizontally();
            //idle2
        GreenfootImage idleTwoRight = new GreenfootImage("idle2.png");
        GreenfootImage idleTwoLeft = new GreenfootImage("idle2.png");
        idleTwoRight.mirrorHorizontally();
            //shoot1
        GreenfootImage shootOneRight = new GreenfootImage("shoot1.png");
        GreenfootImage shootOneLeft = new GreenfootImage("shoot1.png");
        shootOneRight.mirrorHorizontally();
            //shoot2
        GreenfootImage shootTwoRight = new GreenfootImage("shoot2.png");
        GreenfootImage shootTwoLeft = new GreenfootImage("shoot2.png");
        shootOneRight.mirrorHorizontally();
        //setting velocity
        velocity = 0;
        //setting Hero image
        setImage(idleOneLeft);
Any ideas?
Super_Hippo Super_Hippo

2017/10/7

#
Well, if the name of the image is "Idle1.png", then the name in your code should be "Idle1.png" instead of "idle1.png", too.
Beamo Beamo

2017/10/7

#
OHHH! I didn't see the capital... oops. Thanks again!
You need to login to post a reply.