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

2020/6/9

Changed image

Brandman73 Brandman73

2020/6/9

#
When I call the method rotate() for an image: img.rotate(rotation); it rotated the image but also changed the image's white spots to pink is there something I am doing wrong? This also happens with the img.mirrorHorizontally();
danpost danpost

2020/6/9

#
Brandman73 wrote...
When I call the method rotate() for an image: img.rotate(rotation); it rotated the image but also changed the image's white spots to pink is there something I am doing wrong? This also happens with the img.mirrorHorizontally();
I was aware of the red tinting during the one mirror option. I was not aware that rotate also caused red tinting. Be more specific as to your usage of these. Explain what your goal is and show attempted code using rotate. There is most probably a decent work-around.
Brandman73 Brandman73

2020/6/9

#
I am trying to animate an image using rotation, specifically a character that is in water so to swim in a certain direction I commented out the mirrorHorizontally() for testing and it still had the red tint, so that cannot be the problem
public void drawCharacter(int factor)
    {
        
        int rotation = 0,rotation2 = 0;
        
        String up = "Up";
        rotation2 = (int)(90 - -accelX * 9) * 2 - 90;
        if(accelX > 0)
        {
            mirror = true;
            rotation2 += 180;
            rotation = ((int)accelY * 5);
        }
        else if(accelX < 0)
        {
            mirror = false;
            rotation = ((int)-accelY * 5);
        }
        if(rotation2 - 180 > -45 || rotation2 < 45)
        {
            up = "";
            if(accelX > 0)
            {
                rotation2 += 90;
            }
            else
            {
                rotation2 -= 90 + 180;
            }
        }
        GreenfootImage img = new GreenfootImage("characterSwim"+up+"-"+(characterCostume+1)+".png");
        
        
        if(mirror)
        {
            img.mirrorHorizontally();
        }
        
        img.scale(img.getWidth() * factor,img.getHeight() * factor);
        img.rotate(rotation + rotation2 - 90);
        
        screen.drawImage(img,300 - img.getWidth() / 2,300 - img.getHeight() / 2);
    }
danpost danpost

2020/6/9

#
Are you using greenfoot? If yes, is this code in your World subclass or in an Actor subclass?
Brandman73 Brandman73

2020/6/10

#
I am using Greenfoot, this is in my actor class. I did not want to paste the entire source code for the actor since it is about 2000 lines long.
danpost danpost

2020/6/10

#
Brandman73 wrote...
I am using Greenfoot, this is in my actor class. I did not want to paste the entire source code for the actor since it is about 2000 lines long.
Then use turn or setRotation on the actor instead of rotating the image of the actor. You can create an opposite facing image by creating an image of the same size and reversing the order of the colors along each row of pixels. Then use getRotation to determine which image should be used. Using the move method for moving might be handy as a bonus.
Brandman73 Brandman73

2020/6/10

#
I fixed it. I had one actor that would act as the screen using the screen GreenfootImage that covers the entire screen, I changed the needed variables to public static and then used another actor to act as the character, this fixes the problem. Thanks for helping me :)
Brandman73 Brandman73

2020/6/10

#
if you are curious, here is my flipping code:
public GreenfootImage flip(GreenfootImage img)
    {
        GreenfootImage img2 = new GreenfootImage(img.getWidth(),img.getHeight());
        int x = 0;
        while(x < img.getWidth())
        {
            GreenfootImage save = new GreenfootImage(1,img.getHeight());
            save.drawImage(img,-x,0);
            img2.drawImage(save,img.getWidth() - x,0);
            x++;
        }
        return img2;
    }
danpost danpost

2020/6/10

#
Brandman73 wrote...
if you are curious, here is my flipping code: << Code Omitted >>
That will flip the given image with one little problem. In line 9, use "img.getWidth()-1-x".
You need to login to post a reply.