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

2013/5/30

How to handle more than one level

tollpatch tollpatch

2013/5/30

#
My aim is, to have more than one level in a game. I want to use the same actor "Fels" with different images in the different worlds. Here is the beginning of my procject: World -> BeuteltierWelt -> IceWorld Actor -> Fels Within the constructor of the class "Fels" i wrote:
public void Fels()

World hier = this.world();

if ( hier == BeuteltierWelt)
 { setImage (sandrock.png);}
 else
   if (hier == IceWorld)
    { setImage(icerock.png);}
    else
     { setImage( water.png);}
The identification of the calling world doesn´t work. I always see "water". How to write the correct code greetings from tollpatch
danpost danpost

2013/5/31

#
First, the code you gave is not a constructor (constructors do not have return types). Second, 'world' is not a method (maybe you meant 'getWorld'). Finally, if you did mean 'getWorld', it would not work in a constructor because the object being created is not yet in a world. There is a method you can put similar code in that would run once immediately after the object was placed in a world -- the 'addedToWorld(World)' method, which is called automatically (you do not have to call the method for it to execute). Now, before going on, I cannot believe that the code you gave even compiled for many reasons. I want you to copy/paste (literally) that method and post it exactly as it is in your project.
Phytrix Phytrix

2013/5/31

#
Have a look at this scenario. It should help you out if you just look at how to change the world from the Pengu class. http://www.greenfoot.org/scenarios/3061
tollpatch tollpatch

2013/5/31

#
Thanks danpost and Phytrix for quick replies, danpost, its right that some mistakes are in the code which more represent my ideas. Phytrix, your link was very helpful!! I learned to give a value to the constructor methode. My theoretical wiches are fullfilled: One class is used in all worlds, but with different images. In each level each object can apear with its different image. Thanks for support
You need to login to post a reply.