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

2014/10/22

Need help

beginner beginner

2014/10/22

#
I'm a beginner and I want that if I press run triangles appear on screen but nothing happen at the moment. I hope you can help me.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class Label extends Actor
{
    
    
    public Label()
    {
       GreenfootImage img = new GreenfootImage(600,400);
        img.setColor(Color.WHITE);
        img.fill();
        img.setColor(Color.BLACK);
        img.drawString("Dreieck animation",300,200);
           
      
        setImage(img);
         
        }
    public void Act()
        {
            
        drawD();
         
        
            }
    public void drawD()
        {
        GreenfootImage img = getImage();
          int q= Greenfoot.getRandomNumber(255);
          int w= Greenfoot.getRandomNumber(255);
          int e= Greenfoot.getRandomNumber(255);
          img.setTransparency(255);
          int[] a= {Greenfoot.getRandomNumber(600),Greenfoot.getRandomNumber(600),Greenfoot.getRandomNumber(600)};
          int[] b= {Greenfoot.getRandomNumber(400),Greenfoot.getRandomNumber(400),Greenfoot.getRandomNumber(400)};
          img.setColor(new Color(q,w,e));
          img.fillPolygon(a,b,3);
          img.setColor(new Color(0,0,0));
          img.drawPolygon(a,b,3);
          setImage(img);
        
        }
       }
Just the text appear on screen
erdelf erdelf

2014/10/22

#
method names are case sensitive you called the method Act but it needs to be namend act
beginner beginner

2014/10/22

#
thx for your help
danpost danpost

2014/10/22

#
Couple of things here (ok, several): * filling the image with white is not necessary; the background image of the world is white by default, so, seeing through the unused portion of the image of the actor is not a problem (you can remove lines 10 and 11 above); * any triangle covering the drawn text will permamently destroy the text unless you draw the text after each triangle is drawn (copy, or move, lines 12 and 13 to line 39; * line 28 has 'img' refer to the image used for the actor; in other words, 'img' and 'getImage()' will both point to the same memory location where the image of the actor is stored; therefore resetting the image using 'setImage' on line 39 is not needed; * line 32 sets the transparency of the new image to '255'; that value is the default value for new GreenfootImage objects (you can remove that line also).
You need to login to post a reply.