As orx is data driven, here we only need two lines of code to create a viewport and an object. All their properties are defined in the config file (01_Object.ini).
The viewport is associated with a camera which is implicitly created from the info given in the config file. Still in this config file, you can also set their sizes and positions or the object color, scale, rotation, animation, physical properties, and so on. You can even request random values for all these setting without having to add a single line of code.
In a later tutorial we'll see how to generate complex object hierarchies or even a whole scene (all background and landscape objects for example) with only a single line of code.
For now, you can try to uncomment some of the lines of 01_Object.ini, play with them, then relaunch this tutorial. For an exhaustive list of options, please have a look at CreationTemplate.ini.
Creating an object is really simple. However, we first need to make sure that we have loaded the config file where all the object's properties are defined. We also want to display the created object, through a viewport/camera set.
Don't panic! All this is really easy.
In this tutorial, we are loading a config file which is in our parent directory. As you may see, in this case, all the executables are in their own child directory, depending on their build type (mingw, msvs2005, msvs2008, etc…) and we didn't want to duplicate the corresponding config files everywhere. 1)
In our case, loading the config file is done like with this line:
orxConfig_Load("../01_Object.ini");
We then create our viewport. Note that the camera creation is automatically done given the config information stored for this viewport.
orxViewport_CreateFromConfig("Viewport");
We're almost done. We only need to create our object now!
orxObject_CreateFromConfig("Object");
That's it! The object has been created and will be displayed as long as it is in the frustum of our camera.
Now, as we're using Orx's default launcher, we need to declare our plugin entry point (here our Init function). This is easily done with a macro.
orxSTATUS Init(){...} orxPLUGIN_DECLARE_ENTRY_POINT(Init);
As orx is data driven, we don't need to manually load any data, such as a sprites. Everything is handeld for us, with a data manager that will make sure sprites won't be duplicated in memory and freed when not used anymore.
If you look at the config file, in the [Object] section, you'll see that you can specify all the object's properties, such as: graphic (sprite), pivot, color, alpha, physics properties, position, rotation, scale, tiling (repeat), animation, visual FX, etc…
Don't worry, all this will be covered in further tutorials.
Now we have an object, we need to learn how to interact with it. This brings us to our second tutorial: clock.
Source code: 01_Object.c
Config file: 01_Object.ini