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

2015/11/25

Proof which world is currently played.

tmrpcz tmrpcz

2015/11/25

#
Hey, I want to have background music for my game. It starts exactly how it should but i would like to have a different music for the next level. How can I proof which level is currently played, so i can have an if statement to place the stopMusic in ? RIght now my code looks like this:
GreenfootSound hintergrundmusikhalloween = new GreenfootSound("HalloweenMusik.mp3");
    public void act()
    {
        startMusikLevel1();
        if (Greenfoot.setWorld(Level3)==true)!!!!!!!!! THIS DOES'NT WORK !
        {
            stoppMusikLevel1();
        }
    }

    public void stoppMusikLevel1()
    {
        hintergrundmusikhalloween.pause();
    }

    public void startMusikLevel1()
    {
        hintergrundmusikhalloween.play();
        hintergrundmusikhalloween.setVolume(25);
    }
danpost danpost

2015/11/25

#
The 'setWorld' method of the Greenfoot class, first off, is void of a return type and you cannot compare 'true' to a non-existent value. Secondly, requires a World object as a parameter, not a class name. Both of these can be determined by looking at the method description in the Greenfoot class API documentation. You can use the 'instanceof' keyword to ask if any object is of a specific type. As an example of its use, an Actor object might use something like this:
if (getWorld() instanceof Level3)
tmrpcz tmrpcz

2015/11/25

#
it says cannot find symbol - method getWorld() do i have to implement anything earlier ?
danpost danpost

2015/11/25

#
tmrpcz wrote...
it says cannot find symbol - method getWorld() do i have to implement anything earlier ?
I gave an example of its use with code that would be used in a subclass of Actor.
You need to login to post a reply.