Game Development Reference
In-Depth Information
How to do it...
The XML for this recipe can be completed by performing the following five steps:
1. We start by defining a new <controlDefinition
name="gameMessage"> .
2. Inside this, we should add a panel element, and inside this panel element, add
two <control name="label"> elements with the ID #title and other
contents.
3. The panel should also have two effects, one onShow trigger and one onHide
trigger with move and fade effects respectively, as shown in the following code:
<onShow name="move" mode="fromOffset" offsetX="1500"
length="100" inherit="true"/>
<onHide name="fade" start="#ff" end="#00" length="100"
inherit="true"/>
4. In addition to the gameMessage control, we can define another control to be our
messageQueue element. It just needs a horizontally aligned panel, spanning the
whole screen.
5. To make them align with each other, the messageQueue control is added to the
mainScreen.xml file inside the same layer as the console.
Inside MainScreenController , we need to do the following changes:
6. First, add a new int field called messageIndex .
7. Then, we need two methods. One of these is called addMessage that should take
a string as an input.
8. Inside the addMessage method, we define a ControlBuilder method called
messageBuilder . This will create gameMessage controls:
messageBuilder = new ControlBuilder("gameMessage") {{
id("message"+messageIndex);
interactOnClick("removeMessage("+messageIndex+")");
}};
9. After calling the build method on this and supplying the messageQueue ele-
ment as the parent, we can call element.findNiftyControl to set the title
and the text on the labels inside the gameMessage control.
Search WWH ::




Custom Search