Posts Tagged ‘2D’

Unity: Scaling the GUI based on the screen resolution

Click here to read Unity: Scaling the GUI based on the screen resolution

As hinted by other posts, here, you will find how to properly scale the GUI elements based on screen resolution. As one may have noticed, Unity doesn’t scale the GUI elements based on the screen resolution, requiring a script to do the job, which is explained in this post. I will assume that the reader already knows how to create and render GUI elements in Unity using the MonoBehaviour’s OnGUI() function and GUISkin objects.

The best way to explain how to properly scale a GUI element is through an example. That said, for this post, let’s assume that we wanted a yellow rectangle to be rendered at the top left and bottom right corners of the screen, like this: (more…)

Android: take a picture without displaying a preview

Click here to read Android: take a picture without displaying a preview

Accessing hardware functionality when programming for an Android device is generally quite straightforward. The same can be said about writing an Activity that takes a picture, but Android requires a preview of what the camera will capture to be displayed prior to capturing an image. This post explains how to “cheat” this requirement imposed by the OS, and how to write an application that takes a picture and displays it.

An Eclipse project with all the code explained here is available for download at the end of the post.

Before going into the Activity code, the interface layout (the main.xml file) must be edited to add a Surface View and an Image View to the interface. To add an element, just drag and drop it from the list inside your layout, like this: (more…)

Unity: Creating a simple billboard

Click here to read Unity: Creating a simple billboard

Sometimes, when creating a game, there is the need to use a billboard. In the Unity game engine there is no billboard rendering component, and that’s why this post is going to explain one of the options to do so, it’s advantages and disadvantages. It’s not going to require a single line of code, but it’s not going to be the most optimized option either. At the end of the post a Unity project with all the game objects and components configured here is available for download.

To make a billboard in Unity, there is basically three different options: (more…)

Unity: How to create a GUI Sprite Sheet – Part 3

Click here to read Unity: How to create a GUI Sprite Sheet – Part 3

The final part of a series that explains how to create a GUI Sprite Sheet in Unity. This post will focus on explaining how the code works. For those who haven’t read the first and second parts, please do before going any further. As most post series in this website, there is a download with everything that had been explained at the end of the post.

With all images and the GUI Skin already set at the Unity Editor, now we just need some code to render the GUI on the screen. The following script correctly renders separately each element from the sprite sheet, and it’s attached to the Main Camera:

(more…)

Unity: How to create a GUI Sprite Sheet – Part 2

Click here to read Unity: How to create a GUI Sprite Sheet – Part 2

This is the second part of a series that will explain how to create a GUI sprite sheet for Unity. For this part, we will take the images created in the first post and import them to Unity. Also, this post features how to correctly set the images to be part of a GUI Skin object so they can be used as part of a game’s interface.

After having all images correctly placed at the sprite sheet, create a new GUI Skin by right-clicking anywhere inside the Project tab and select the following: Create->GUI Skin. Then, import the images in Unity, by dragging and dropping them inside this tab. It’s a good idea to put everything GUI related at the same folder, like this: (more…)