Archive for the ‘Programming’ Category

Using static variables in Unity3D

Click here to read Using static variables in Unity3D

This post explains how to use static variables when programming scripts for the Unity3D engine. The example scripts in this post are written in C#, but the same guidelines apply for JavaScript.

Before delving deeper into the subject, it goes without saying that static variables should be avoided at all costs, for a great number of reasons that can be easily be found on the internet. It’s better to use a Singleton creational pattern in most cases. with that in mind, here’s a short definition of static variables: they are variables that belong to a class, and not the objects the class creates. This means that static variables retain the same value, regardless of the object from a given class. Another characteristic is that, as long as the class is in the memory, they are still valid references. Static variables are initialized by the compiler right before the class creation, and before any other variables or methods. But what does it mean for Unity3D scripts?

Continue reading: “Using static variables in Unity3D”

Android: Changing the animation between Activities

Click here to read Android: Changing the animation between Activities

This post features how to change Android’s default animation when switching between Activities. Before reading the rest, please know that the code that changes the standard animation be found at the API Demo that comes with the Android SDK. But since there’s a lack of proper documentation regarding this subject and it’s difficult to find a place explaining it, here is a post that helps in aiding these two problems.

So, the code to change the animation between two Activities is very simple: just call the overridePendingTransition() from the current Activity, after starting a new Intent. This method is available from Android version 2.0 (API level 5), and it takes two parameters, that are used to define the enter and exit animations of your current Activity. Here’s an example: Continue reading: “Android: Changing the animation between Activities”

Configuring openFrameworks add-ons in Codeblocks

Click here to read Configuring openFrameworks add-ons in Codeblocks

At some point, when using openFrameworks to create interactive applications, one needs to use some of the bundled add-ons. This post will explain how to configure your Codeblocks project to use these add-ons and how to include the OpenCV add-on to your project. Before continuing, you should know there is an automated tool that helps the programmer in this process, specially designed to easily configure openFrameworks projects and add-ons at Google Code: ofcodeblocksplugin (official forum thread here).

Differently from this tool, this post explains on how to manually include the add-ons to your openFrameworks project. The process described here was done using Codeblocks 10.05 and openFrameworks 0.62 on a computer running Windows.

Continue reading: “Configuring openFrameworks add-ons in Codeblocks”

Unity3D: Creating a GUI with both 3D and 2D elements

Click here to read Unity3D: Creating a GUI with both 3D and 2D elements

This post explains how to create a GUI on the Unity3D game engine that has both 2D and 3D elements in it. Some may say that is just a matter of setting up a new camera with a dedicated culling mask just to render the 3D elements on the GUI. While this is partially true, adding a 2D image using a script with GUI function calls will cause the 3D image to be covered by the 2D image. That’s why this post will focus on how to set a GUI that has a 3D element with a 2D background.

As usual, at the end of the post, a Unity3D project is available for download with everything that was explained here.

Continue reading: “Unity3D: Creating a GUI with both 3D and 2D elements”

Using C# delegates in Unity3D scripts

Click here to read Using C# delegates in Unity3D scripts

When Unity3D 3.0 came out, it not only fixed a lot of bugs and added features, but it also upgraded the Mono version being used, including C# language features like namespace support, linq and delegates. This post is going to be about the latter, explaining what is a delegate and what benefits it could bring when using it to develop games on Unity3D.

Basically, in C#, a delegate is a reference to a method or to a group of methods that have the same signature (returns the same type and has the same parameters). A better explanation can be found at Microsoft’s MSDN C# documentation: Continue reading: “Using C# delegates in Unity3D scripts”