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

2012/10/19

Why wont this work?

hamchi hamchi

2012/10/19

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class instructie here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class controlsBord extends Actor
{

    public void controlsBord()
    { 
        checkMouse();
   
         
    }

    public void checkMouse() 
    {
        if(Greenfoot.mousePressed(this))
        {
            
            Greenfoot.start();
            getWorld().removeObject(this);

        }
        else{
        }
    }    
}
World cass
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;

public class Board extends World
{
controlsBord bord = new controlsBord();
   Paddle paddle = new Paddle(); 
    /**
     * Constructor for objects of class Board.
     * 
     */
    public Board()
    {    
       super(460, 520, 1); 

addObject(bord, getWidth() / 2, getHeight() /2);
         
      addObject(paddle, getWidth() / 2,getHeight() - 40);
      addObject(new Ball(),paddle.getX(),paddle.getY() - 15);
      Ball.geschoten = false;
    }
     


    
    
   

}

hamchi hamchi

2012/10/19

#
i am trying to get it to, run the game when the object controlsBord is clicked on. and remove the object
danpost danpost

2012/10/19

#
The methods 'controlsBord' and 'checkMouse' in the controlsBord class are not being called to execute. And, besides, will not continually check for mouseClick until the program is started and the method 'controlsBord' is called to execute. Hence, the command 'Greenfoot.start();' is useless within a key or mouse checking block. Anyways, the user can just click on the 'Run' button to start the scenario; so, why the extra code? If you want the scenario to start automatically, put the command in the world constructor.
hamchi hamchi

2012/10/20

#
thanks mate, i figured i would add that because it whas a bit of hassle to press run to execute the program then press another button to start the game. thanks anyways, i just added the start() method in the world's constructor like you sed.
You need to login to post a reply.