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

2017/5/7

How do I use methods from the World?

Unknown6415 Unknown6415

2017/5/7

#
if I write
Unknown6415 Unknown6415

2017/5/7

#
Ups, I accidentally posted it. Well, I just write it here:
public class world extends World
{
GreenfootSound backgroundmusic= new GreenfootSound("backgroundmusic.mp3");

public void bgstart()
    {
        backgroundmusic.playLoop();
    }
...
and then how can an actor use this void? I tried
getWorld().bgstart();
but this doesnt work
danpost danpost

2017/5/7

#
You can use this:
((world)getWorld()).bgstart();
which will allow the compiler to find the method in your 'world' class (as opposed to only looking in the 'World' class, and Object class, for it). However, as the background music is something you would want global access to, you could change line 3 to:
static GreenfootSound backgroundmusic= new GreenfootSound("backgroundmusic.mp3");
and then, you can use:
world.bgstart();
from anywhere.
Unknown6415 Unknown6415

2017/5/7

#
Oh yes thanks, I found the exact same way you wrote I time ago in another discussion This works, thanks
You need to login to post a reply.