
Learning AndEngine
By :

Another way to output text on the screen is using toasts. A toast is a simple message widget that can provide feedback about an operation in progress. It's a core Android widget, not an AndEngine component, but we can nevertheless use it in our game.
The easiest way to show a toast is to use a static method provided by the Toast
class. In a general Android app, we can simply call this as follows:
Toast.makeText(activity, "Hello World", Toast.LENGTH_LONG).show();
We can also call a toast inside the activity itself. This can be done as follows:
Toast.makeText(this, "Hello World", Toast.LENGTH_LONG).show();
The makeText()
method creates the Toast
object. It takes three parameters: the context (activity), the text to show, and the length of the toast, which can be one of the following two types:
Toast.LENGTH_LONG
Toast.LENGTH_SHORT
Finally, we call the show()
method on the newly created Toast
object.
However, if we try to call this object inside the game, it won't work. This is...
Change the font size
Change margin width
Change background colour