Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public Jerry() //class is named "Jerry", it's an extension of the "Animal" class
  2. {
  3. image1 = new GreenfootImage("A.png");
  4. image2 = new GreenfootImage("B.png");
  5. setImage("A.png");
  6. blink();
  7. }
  8.  
  9. public void blink()
  10. {
  11. if ( getImage() == image1 ) // This makes the object constantly switch between
  12. { // two images. I understand how this works...
  13. setImage(image2);
  14. }
  15. else
  16. {
  17. setImage(image1);
  18. }
  19. }
  20.  
  21.  
  22.  
  23. however, that's if I want the object to switch between two images, like a walking cycle, but this is not the case.
  24. I feel like I need to only declare one image, then declare its transparency as a variable, something maybe like
  25. transVariable = getTransparency()
  26.  
  27. Then, I think the code would maybe look like
  28.  
  29. public Jerry()
  30. {
  31. image1 = new GreenfootImage("A.png");
  32. image2 = new GreenfootImage("B.png");
  33. setImage("A.png");
  34. transVariable = getTransparency();
  35. blink();
  36. }
  37.  
  38. public void blink()
  39. {
  40. if ( getImage() == image1 )
  41. {
  42. setImage(image2);
  43. setTransparency(0);
  44. }
  45. else
  46. {
  47. setImage(image1);
  48. setTransparency(transVariable);
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement