VixMLSearch |
Building A SceneThis document describes the main concepts involved in building interactive media in VixML. Once you are familiar with these concepts, you can find more detailed information on the VixML format in the Reference Guide.Table of contentsVixML Media FormatVixML media is stored as a directory containing an index.xml file that describes a scene, as well as any resources the scene requires. The VixML media directory may have any directory structure, though it is a common convention to place resources into separate subdirectories such as "sounds", "music" and "images".To create a new piece of VixML media, create a new directory with a basic index.xml file, and add any resources your scene will require. VixML Scene OverviewA Scene is the root element of all VixML files. It is used to contain all elements and events associated with the animations. VixML scenes are built using a couple of simple elements:
Of the items listed above, objects, controllers and triggers are all persistent elements in the scene which are encoded in the scene file. Messages are not persistent elements in a scene, but are instead generated during runtime when a trigger fires or in response to other events. Objects may be hierarchically grouped together in groups of zero or more objects. Groups are themselves objects, and may be added to other groups. All properties of objects (such as location, rotation, scale and color) are interpreted as relative to their parent objects, so if a group moves, all of the objects inside of it also move. This is true down the entire object hierarchy such that an object's ultimate state is affected by all of its ancestors. Groups are not only used for holding multiple objects–they are also used as separate logical units that can have their own triggers and controllers. Used in this way, it is not uncommon for a group to contain only a single object or to contain no objects at all. An example of this usage of groups is described in this VixML cookbook entry. Each object may have any number of controllers and any number of triggers, though only one controller may be active at any time for an object. Affecting an object with more than one controller at a time can be accomplished by placing one of the controllers in a parent group (as described here). All triggers are always active for an object (unless they make use of optional "scene state" functionality, described here. At the top-level, each scene must contain a single root object, which is typically a group (otherwise it would be impossible to include more than one object in the scene). The above diagram is a representation of the scene. The labeled components are as follows:
Object OrderingObjects are drawn in the order in which they appear in the scene, from top to bottom, such that objects which appear later in the scene are drawn on top of objects which appear earlier. Mouse clicks and other events give priority to the objects "in front" (i.e., those which appear later in the VixML definition).Scene "State"Complex scenes may include multiple modes of operation, or "states" and may require that certain events trigger different actions depending on this state. For example, a scene that has a "menu" state and a "gameplay" state may treat mouseclicks differently in each state. Scenes have a global "state" string which is used to indicate the current state of a scene, and triggers may specify an optional state to be active only when the scene is in the specified state.States can be set using the statechange Steps of a sequencecontroller. If a trigger does not have a state string, then it is always active. Tutorial: Building a Ringing BellTo illustrate the base capabilities of VixML, let's animate a simple bell complete with motion and sound effects. For interaction, when the iPhone is shaken, we will trigger the bell to shake and play a ringing sound.1. Assemble the assetsIn order to assemble this animation, we'll need two assets: an image of the bell and a sound effect to play when the bell is shook. For the purpose of this example, these assets have been provided for you and are located under "Samples" >> "01 Bell" folder found in the VixML SDK bundle. They are called bell.png and jingle.wav.2. Creating the VixML: Organize the sceneLet's start writing some VixML. We'll begin by creating a scene with the assets on stage. Within a text editor, add the following VixML code:<?xm<x>l version="1.0" encoding="UTF-8"?> <scene> <group> <sprite image="bell.png" name="background" /> </group> </scene> Save this file as index.xml within the same folder as your other assets. Test that you have created this successfully by using the VxEngine to execute the index.xml file. Run the VxEngine and click "Open" and select the index.xml file. You should simply see an image of the bell displayed. 3. Adding SoundAll animations and sound effects within VixML are handled within a controller. Using your text editor, within the index.xml file, add the jingle.wav sound file using a sequence controller. The code should look similar to the following:
Notice how the jingle.wav sound file will play when the scene is initially loaded because the "trigger" is set to "on 4. Triggering animation based on a shake event.Let's change the bell to only play a sound when the iPhone is shaken. Within your index.xml file add a shake trigger to send out a shakemessage message when the iPhone is shaken. Then change your sequence controller to listen for the shakemessage instead of on
If you "Reload" the index.xml file within the VxEngine?, you can now press the "Shake" button at the bottom and that should play the sound file. 5. Animate the bellFinally, we should animate the motion of the bell every time a user shakes their device. Within your index.xml file add various move steps within your sequence controller to rotate the bell image. When finished, your code should look like the following:<?xm<x>l version="1.0" encoding="UTF-8"?> <scene> <group> <!-- when we get a shake, send out the message "shakemessage" --> <shaketrigger tolerance=".1" message="shakemessage" /> <!-- when we get a shakemessage, animate the group back and forth and play a sound --> <sequencecontroller trigger="shakemessage"> <sound file="jingle.wav" /> <move type="absolute" duration=".08" rotation="15" /> <move type="absolute" duration=".08" rotation="-15" /> <move type="absolute" duration=".08" rotation="10" /> <move type="absolute" duration=".08" rotation="-10" /> <move type="absolute" duration=".08" rotation="0" /> </sequencecontroller> <sprite image="bell.png" name="background" /> </group> </scene> Within the VxEngine?, if you "Reload" the index.xml file you should see the bell animate and play a sound every time you press the "Shake" button at the bottom. Coding GuidelinesCoding ConventionsGive every tag a descriptive name–all VixML tags accept name attributes. While these names are not widely used within VixML at the moment, it is still important to give descriptive names to all objects.
Image/Sound Size and QualityTargeting virtual goods to mobile devices presents a number of challenges when compared to content development on the desktop or the web:
In order to ensure that virtual goods run efficiently on mobile devices, the following guidelines should be followed:
Size limits and guidelines for deploying content on the iPhone.
Interpreting Coordinates, Colors and InputsThe default coordinate system is a 2D orthographic view centered at (0,0) and with the same width and height as the device. The "up" direction is represented by a positive vector on the Y-axis. On the iPhone, when in the portrait orientation, this means the size is 480x320 and that the coordinate at the lower left corner of the window is (-240,-160).Colors are represented as a vector of 3 floating point values from 0.0 to 1.0 which represent intensity of the color channels red, green and blue respectively. The alpha value is also a floating point value from 0.0 to 1.0, but is encoded separately from the color vector. Input values:
MetadataIn addition to the VixML content, scene files may also contain metadata tags at the start of any scene. These metadata tags contain information which is generally not used by the scene directly, but which may be interpreted by the specific player application. For example, the TrueFlirt application may expect scenes to contain flirtback data in the metadata section.
|