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

2014/10/18

How would I make a win message?

rrose5 rrose5

2014/10/18

#
When a player reaches a certain actor how would I make it so that a picture would go on the screen that says :"You win!" or something along those lines. Also how would you add sound to the win message?
Alwin_Gerrits Alwin_Gerrits

2014/10/18

#
Well sounds are from the standard libraries, just look them up in the file you have the program in and you should have a decent idea of the commands you can use. As for the win message... you could use a scanner like 'isTouching' or 'intersect'... there are tons of options. After you chose oone simply use it in an if-statement with the object you want to use to end your game. I would recomment placing it in your main actor (seen your talking about something that sounds like a platform game i would say put it on the player objects code). Then when they touch you can call for a message to pop up. Even though I personally wouldn't recommend using this as it can become problematic you can use the following command. But you have to find out how it works yourself because I'm not gonna write the entire code for you unless you really can't find the answer. Also, don't forget the library!
import javax.swing.*;
JOptionPane.
the optionpane command is a lot longer, but then again it has a lot of differend uses and it will stop your game for the time it's beïng displayed. I would however highly recommend putting a safety on this!!! If your code is gonna run into it to fast you might end up beïng unable to close your code. So before you put this one into practice be sure to make a copy of your code as it is now and put some kind of safety guard in place. Like a counter that gets upped 1 if your if-statement is true then put the counter in your if-statement which only makes it react at counter==0. Like this:
if (isTouching(endobject.class) && counter==0)
{
  JOptionPane........;
  counter++;
}
I hope this helped seen i'm new to greenfoot myself, so if it doesn't make sure to post that on this discussion so other people know it isn't solved!
Super_Hippo Super_Hippo

2014/10/18

#
I think it would be much easier if you create a actor which uses the "You win" message as its image and display it when you reach you object. (Make sure the actor is the first in the 'setPaintOrder' method or remove all other actors.) If the game ends there and nothing else has to be there anyway, you could also just change the background of the world to this image and remove all actors from the world. With this, you won't create a (sometimes) annoying pop-up.
You need to login to post a reply.