If I have an actor and I double click it, it expands. I want to be able to double click it again, and it shrink back to the normal size. Is there any possible way of doing this?


1 2 3 4 5 6 7 8 9 | // using these int fields int ten = 10 ; // larger size of a dimension int five = 5 ; // smaller size of the same dimension int toggleValue = five; // current dimension size // the following will toggle the 'toggleValue' field between the two values, 'ten' and 'five': int sumValue = ten+five; toggleValue = sumValue-toggleValue; // or simply toggleValue = 15 -toggleValue; |
1 2 3 4 5 6 7 8 9 | // using these int fields int ten = 10 ; // larger size of a dimension int five = 5 ; // smaller size of the same dimension int toggleValue = five; // current dimension size // the following will toggle the 'toggleValue' field between the two values, 'ten' and 'five': int sumValue = ten+five; toggleValue = sumValue-toggleValue; // or simply toggleValue = 15 -toggleValue; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | if (Greenfoot.mouseClicked( this )) { MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse.getClickCount() == 2 ) { int ten = 10 ; // larger size of a dimension int five = 5 ; // smaller size of the same dimension int toggleValue = five; // current dimension size int sumValue = ten+five; toggleValue = sumValue-toggleValue; if (toggleValue == 10 ) { GreenfootImage image = new GreenfootImage( "German SdKfz 234_1 Edit.png" ); setImage(image); } else if (toggleValue == 5 ) { GreenfootImage image2 = new GreenfootImage( "German SdKfz 234_1 Less.png" ); image2.scale( 75 , 75 ); setImage(image2); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // the field (outside any method, but inside the class) private int imageNumber; // your if block above, revised if (Greenfoot.mouseClicked( this )) { MouseInfo mouse = Greenfoot.getMouseInfo(); if (mouse.getClickCount() == 2 ) { imageNumber = 1 -imageNumber; // toggle value between zero and one String suffix = "Edit" ; // assume zero value if (imageNumber == 1 ) suffix = "Less" ; // adjust if one value setImage( new GreenfootImage( "German SdKfz 234_1 " +suffix+ ".png" )); // set image if (imageNumber == 1 ) getImage().scale( 75 , 75 ); // scale if one value } } |
1 | String suffix = imageNumber == 0 ? "Edit" : "Less" ; |