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

2012/4/19

chapter 6 exercise 6.34

jpkenned jpkenned

2012/4/19

#
I'm trying to make the color of my actor change when it bounces off the edge. I know how to right the if part but i cant figure out how to write the code to randomly change the color. any help would be appreciated. thanks
jpkenned jpkenned

2012/4/20

#
This is what I have so far and it changes colors, but also turns my circles into uniform squares. If you have the book I'm trying to do exercise 6.34.( when planets bounce off the edge they change colors.) private void changeColor() { int r = Greenfoot.getRandomNumber(255); int g = Greenfoot.getRandomNumber(255); int b = Greenfoot.getRandomNumber(255); GreenfootImage image = new GreenfootImage ("Body.png"); image.setColor (new Color(r,g,b)); image.fill(); setImage (image); }
danpost danpost

2012/4/20

#
Instead of 'fill()', try the GreenfootImage method 'fillOval(int, int, int, int)'.
You need to login to post a reply.