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

2016/4/28

MouseObject help

Walker Walker

2016/4/28

#
So for right now i want it so that if i click on gaster it brings me to the next world(named Opening) just as a test, but it is not working so here is my code please help
/**
     * Act - do whatever the Soul wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        checkKeyPress();
        
            if ( touchingObjectBlast() )
            {
                 /**
                  * WIP
                  */
        }
        
          if (Greenfoot.mouseClicked(Gaster.class)) 
          {
        Greenfoot.setWorld(new Opening());
       }
    }   
danpost danpost

2016/4/28

#
The action you require, which you represent (as code that will not compile) from line 16 through 19 is better off placed in the Gaster class act method. The reason is does not compile is that the Greenfoot class method 'mouseClicked' requires an object of type World or Actor (or 'null' if none is to be specified -- or, if the click can be anywhere). You cannot click on a class; you click on objects. In the Gaster class, you can use 'this' as the object:
if (Greenfoot.mouseClicked(this))
You need to login to post a reply.