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

2014/2/9

cannot find symbol- method getOneObjectAtOffset(int, int,java.lang.Class<Player>)

mattman2006 mattman2006

2014/2/9

#
I'm attempting to create a small game and trying to insert a Game Over screen. This is my current code:
1
2
3
4
5
6
7
8
9
10
public void GameOver()
{
    Actor Player = getOneObjectAtOffset(0, 0, Player.class); //This sets this to the Player class.
                                                             //This is also my problem
    if (Player = null)
    {
        getWorld().removeObject(Womboss);
        addObject(gameover, 1500, 1500);                     //This creates the game over screen in the center of the world and removes the Womboss (boss)
    }
}      
I have put this code into my Gamespace class and getting this error: cannot find symbol- method getOneObjectAtOffset(int, int,java.lang.Class<Player> Please help as I have tried many different methods and none of them work. Thanks in advance!
danpost danpost

2014/2/9

#
It appears you do not know at what time to use what method. For example, take lines 7 and 8. The first line starts with 'getWorld' which is an Actor class method and the second starts with 'addObject' which is World class method. Unless you wrote one (or both) of those methods into this class, there is a definite problem. The class cannot be both an Actor subclass AND a World subclass, so one of the two lines is faulty. All non-static methods are executed on an object. The object is given before the call. For example:
1
2
3
4
addObject(actor, x, y);
// the object is the world with which the actor is being added to
// it is equivalent to coding this
this.addObject(actor, x, y);
When the object is not given before the call, the object is the same as the object the code is currently being executed for (or on). Since 'getWorld' is an Actor class method, you cannot start a line with it in a World subclass; only in an Actor subclass. The same goes with 'getOneObjectAtOffset'. If the 'GameOver' method is in a World subclass, you cannot start a line with that. You need to execute the method on an Actor object. Even then, because the method is protected, you cannot even use it outside an Actor subclass. Line 5 is bad in that a single equal sign will set Player to 'null' and 'null' is not a boolean and cannot be used as a condition in an 'if' statement. Sidenote: fields, like your 'Player' field, by convention, should begin with a lowercase letter. One last thing, if (1500, 1500) is the center of your world then your world would be 3000x3000. Everyone will end up with scrollbars and no one will want to play your 'small', as you described above, game. I personally would try not to exceed 800 to 1000 x 600.
You need to login to post a reply.