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

2012/3/17

How to flip image

1
2
armoredarmada armoredarmada

2012/3/17

#
Can someone show me a line for flipping an image when a is pressed, I designed a helicopter but when i have it rotate the other way, its upside down. Someone show me a line or example I would use, thats the easiest way I learn.
Starsonovasa Starsonovasa

2012/3/17

#
You could just create a mirror image in paint. Then, when you press a, you make the program check which image is currently set, and then make the program set the other image.
Starsonovasa Starsonovasa

2012/3/17

#
You could just create a mirror image in paint. Then, when you press a, you make the program check which image is currently set, and then make the program set the other image.
armoredarmada armoredarmada

2012/3/17

#
Can you give me the code to show a mirror immage
danpost danpost

2012/3/17

#
When you turn to go back from right to left, you need to do this.
Duta Duta

2012/3/17

#
danpost wrote...
When you turn to go back from right to left, you need to do this.
GreenfootImage img = getImage();
img.mirrorVertically();
setImage(img);
or just
getImage().mirrorVertically();
armoredarmada armoredarmada

2012/3/17

#
say the code worked duta, but since Im holding down a, the image keeps flipping.
armoredarmada armoredarmada

2012/3/17

#
say I made a mirror image, whats the code to use it using isKeyDown
Starsonovasa Starsonovasa

2012/3/17

#
First create a boolean named isDown and set it to equal false. Then code this in where it is necessary.
if(Greenfoot.isKeyDown("a") && !isDown)
{
    /**
     *insert method for flipping picture
    **/
    isDown = true;
}
if(!Greenfoot.isKeyDown("a") && isDown)
{
   isDown = false;
}
armoredarmada armoredarmada

2012/3/17

#
what? It cant be if(Greenfoot.isKeyDown("a")**method for inserting second picture** and how do I use the second photo of the flipped heli? please say in BASIC terms because im still new to this and I need to understand it you guys r too smart!
danpost danpost

2012/3/17

#
This does not require a second picture. You are not inserting a second picture; you are merely manipulating the one you are already using. It also might be better to use
if("a".equals(Greenfoot.getKey())
which will act only once each time the key is released. This should probably work for you
if("a".equals(Greenfoot.getKey())
{
    turn(180);
    getImage().mirrorVertically();
    // this last line gets the current image and 'flips' it
}
armoredarmada armoredarmada

2012/3/17

#
ok forget that, I am trying new tactic where heli is always pointed right. I want to make the flight mroe real by having a wait line so it moves left or right for 3 seconds, then stops. How would I do that?
danpost danpost

2012/3/17

#
The ways I can immediately come up with are these: (1) determine at what x (how far across the screen, left to right) it would end up at and just check to see if is at or past that mark; (2) count the frames (determined by frames per second * 3) and check to see if count is equal to or greater than that number; or, (3) use an actual timer to count off the 3 seconds and when time is up, stop the heli (you can download a simple millisecond timer from here to see how to use one)
armoredarmada armoredarmada

2012/3/18

#
say Ok I finally figured out how my helicopter will fly, i press q or e to face left or right, and then use a and d to lift and lower my nose, if the angle of the nose is >= / <= a certain degree, then my heli moves in the direction is facing. but the only issue i have at the moment is how to set the image to heli1 (my mirrored heli). what is the code for it? I tried setImage("heli1") as the statement but a java window pops up with something about cant find heli1. in Map (the World's subclass) I put heli1 heli1 = new heli1(); but that still doesnt work. PLEASE tell me the code of how to set its image to heli1!
danpost danpost

2012/3/18

#
You need to include the suffix in the filename (.png .jpg or .gif), and create an image to set the actor to. So, if it is a '.png' file, then
setImage(new GreenfootImage("heli1.png"));
There are more replies on the next page.
1
2