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

2014/4/16

How do I make words in a string appear and go across the screen?

hugotherobot hugotherobot

2014/4/16

#
I am making a typing game where the player has to type words that appear on the screen and has a limited time before the word disappears, but I cant figure out how to code so that my string of words appear one by one and float across the screen. If he misspells or can't type it fast enough a tally mark should appear on the screen too to indicate that he lost a point. Can anyone help? So far I only have my string of words.
1
2
private String[] words = { "APPLE", "OREOS", "ODDFUTURE", "MAGE""FROZEN",
                           "FIGGNEWTONS", "MEWTWO", "PIKACHU", "TOYMACHINE", "BANANA" };
davmac davmac

2014/4/16

#
I think the next step is to create an actor class for representing a word on the screen. You can have a constructor which takes the string as a parameter, and which sets the image of the actor to be the given word (you can use the GreenfootImage constructor which takes a string).
hugotherobot hugotherobot

2014/4/16

#
how would i go about doing that? :/ *sorry im new to programming*
danpost danpost

2014/4/16

#
First create a new Actor subclass and name it something like 'Text'. Open up the code editor for that class and find the constructor ( 'public Text()' ). Add the words 'String word' between the parethesis; this will facilitate in receiving the word so the proper image can be set to the new 'Text' object. Between the curly brackets, create an image of the 'word', by using the GreenfootImage constructor that creates the image of a String, and use the 'setImage' method of the Actor class to set the image of the actor to that image. In the world class, you can now create an Actor object that displays a word by using Actor actor = new Text("word to display"); Then, you can add that 'actor' into the world. The next step would be to give it the behavior you want (moving across the screen and disappearing after the word is keyed in properly or its life-span has expired).
You need to login to post a reply.