Now I have another class, named Car and one subclass, Redcar. In Greenfoot, I have a world class, let's call it World. I'm very noobish when it comes to static/non-static, and I'm iffy on instances also. But this will only work if you only got one instance of this object in your world, because static variables have got the same value for all instances of the object. 1 I'm using Greenfoot at the moment, learning Java. If(coin.getClass(). Then you can excess this value like you are trying to do. It was causing me to have to write multiple versions of the same function in the player.class, aka Mine(Iron iron), Mine(Copper copper), etc etc. GetWorld().addObject(havecoin, 300, 300) The only thing that was different was coloring and name and what inventory slot it goes into. private static boolean isCrankTurned=false Īctor havecoin = new Message("Its a penny") * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Inspector wants to do. ![]() The addObject method is a World class method that adds a new object to the. ![]() * Write a description of class Inspector here. You will refer to this documentation often. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) The Timer class would look something like this: You would add an instance field to the Timer class to hold a PlayWorld object and add an argument to the Timer constructor to pass the PlayWorld object to it. I think what you want is: getWorld ().addObject (new M圜lass (), x, y) This will create a new 'M圜lass' object and add it to the world at (x, y) from any. Let us say your world class is called 'PlayWorld' that the method is in. Let's say you want to create an object from the class M圜lass, do this: M圜lass newObject new M圜lass () After this, you can use the newObject for whatever you want. ![]() Because the timer is not added to the world, it needs to be 'given' the world object. Now, you want that timer object you created to, let us say, call a method in your world class that ends the game playing time and shows a final score screen. For example, let us say you had a Timer class and create a timer object that you do not place in the world (in fact, if you never add any Timer objects into the world, you should probably drop the 'extends Actor' part of the class declaration statement). Then you would not use 'getWorld()' but the reference given. The methods function is to remove the Startscreen, Desciption and Buttons after the user selects a gamode through the buttons and presses enter. Really, the only issue is the with the object not placed in the world, there is no reference to the world unless you pass the world object or any actor object that is in that world to the method in question. I tried different syntaxes for removing the Object but everytime I got a NullPointerExeption.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |