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

2014/1/26

message with the actor

JustMe JustMe

2014/1/26

#
If an object spawn the summary message appears in my screen. but my problem is that the message appears 3 times in the 3 places. What i want to do is that when the first object appears, the first message line appears and when the 2nd object appears the second message appears in the second line (world class) if (spawnCounter++ > 625) { addObject(new cc_Thief(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(470)); addObject(new cc_Fire(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(470)); addObject(new cc_Accident(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(470)); // Call setMessage method in SummaryScreen class ((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage("Er is Vuur!"); ((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage("Er is een dief gesignaleerd"); ((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage("Botsing in Rotterdam"); spawnCounter = 1; } (SummeryScreen class) public void setMessage(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 510); getWorld().addObject(new cc_TextField(380, 20, message,20),600, 530); getWorld().addObject(new cc_TextField(380, 20, message,20),600, 550);
JustMe JustMe

2014/1/26

#
i hope you'll understand what i mean
danpost danpost

2014/1/26

#
Your 'setMessage' method brings in one String object per call and executes all three lines during each call. Therefore, all three messages are being displayed three times (once on each line); except that each successive call overwrites the previous messages on all three lines. So, you end up with the last message being displayed three times (once on each line). You either need to bring in an array of Strings and display each element of the array on different lines or alternate the 'setMessage' and 'addObject' lines in the same method.
JustMe JustMe

2014/1/26

#
i allready have what i want, but my new question is how can i remove the message when the actor is gone
JustMe JustMe

2014/1/26

#
i was 1 second behind your post danpost but i found something i guess because this works a little bit i have made this of it. but i think that im gonna have problems now when i remove an object that it is gonna be difficult to also remove of replace the text public void setMessage(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 510); // Toont een message op het scherm als er een nieuwe calamiteit is. } public void setMessage1(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 530); } public void setMessage2(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 550); }
danpost danpost

2014/1/26

#
Controlling the message displayed can be made difficult, or it can be made easy. If you maintain one cc_TextField object at each of the three locations, then you can have the new one at a location remove the old one at that location and use an empty string for the message that 'clears' or 'removes' the message. This is done by utilizing the 'addedToWorld' method:
// in the cc_TextField class, add the following method
public void addedToWorld(World w)
{
    w.removeObjects(getObjectsAtOffset(0, 0, cc_TextField.class));
}
and just 'setMessage' to "" to clear or remove a message.
JustMe JustMe

2014/1/26

#
i think i've done something wrong because nothing happends
JustMe JustMe

2014/1/26

#
i dont really understand the setMessage thing what i have to do
danpost danpost

2014/1/26

#
To clear a message, use something like this:
((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage2("");
JustMe JustMe

2014/1/26

#
im really sorry but i can't figure it out right now, i think im thinking to difficult. maybe 2 long behind my computer. im going for a run outside. ill be right back and then i will try it again What i have now is: in the cc_Textfield: public void addedToWorld(World cc_Rotterdam) { cc_Rotterdam.removeObjects(getObjectsAtOffset(0, 0, cc_TextField.class)); } in the cc_SummeryScreen: public void setMessage(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 510); // Toont een message op het scherm als er een nieuwe calamiteit is. } public void setMessage1(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 530); } public void setMessage2(String message) { getWorld().addObject(new cc_TextField(380, 20, message,20),600, 550); } in my cc_Rotterdam (world) public void act() { // Add new objects to map. Max height = 470 (this will not hit the controlpanel) if (spawnCounter++ > 625) { addObject(new cc_Thief(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(470)); addObject(new cc_Fire(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(470)); addObject(new cc_Accident(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(470)); // Call setMessage method in SummaryScreen class ((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage("Er is Vuur!"); ((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage1("Er is een dief gesignaleerd"); ((cc_SummaryScreen) getObjects(cc_SummaryScreen.class).get(0)).setMessage2("Botsing in Rotterdam"); spawnCounter = 1; }
danpost danpost

2014/1/26

#
Are you creating and adding a cc_SummaryScreen object into the world anywhere?
JustMe JustMe

2014/1/26

#
i am trying but dont know really how and where. what i dont understand is that i allready have that kind of text in my world and then i have to create another one??
danpost danpost

2014/1/26

#
JustMe wrote...
what i dont understand is that i allready have that kind of text in my world and then i have to create another one??
How are we to know that? you are not giving us enough information to help you properly. This is what I am getting from what you have stated so far. You have a SummaryScreen object in the world that will control 3 TextField objects. You are trying to change he text fields to display different lines of text.
JustMe JustMe

2014/1/26

#
im sorry i think there is an misunderstanding. i had a code in the beginning where i wrote a code that were i can get 3 different lines in my field when my actors respawn. but my new question was if it was possible to get rid of a text when one actor dissapear. sorry for the misunderstanding
You need to login to post a reply.