2D graphics

Xtreme3D

12. 2D graphicsLesson 12
2D graphics

Level: medium
Version of the Xtreme3D: 3.0.x
Author: Gecko

Xtreme3D allows you to draw not only 3D objects, but 2d is a screen text and sprites on screen. On-screen text is displayed on top of the ������������� images and applies for the submission of some textual information in the game: the number of lives or cartridges, different messages, debug data and etc. The on-screen sprites is simply 2D images that can be used to display user interface elements - the sight, icons, the scale of energy, etc. Also you can make the game menu with the background is more preferable than the Create menu via the built-in graphics Game Maker, as in this case, you can draw the menu on top of the 3D-scenes that looks very stylish.

Text objects use special font objects, storing images of text characters, letters, numbers, and punctuation. These images can be set in two ways: to generate from the system of vector fonts in Windows or download from the file. The second is more preferable as you can draw in the graphical editor font size of any color and complexity, with any symbols and in any language, while support for system fonts, severely limited (supported only latin). But the vector fonts, there is one indisputable advantage is the scalability without loss of quality: that is, you can from one and the same font system to generate symbols of different sizes.

The code for the creation of the font and the on-screen text is as follows:

Font = WindowsBitmapfontCreate('Arial', 14, 32, 95);
Text = HUDTextCreate(font, 'Hello, World!', the global.front);

Please note that we specify the root object of global.front as a parent object text - This ensures that the text will ��������� after the 3d scene.

Created by the text can be modified - ask him the color and transparency, as well as the position and rotation:

HUDTextSetColor(text, c_red, 0.5);
ObjectSetPosition(text, 100, 100, 0);
HUDTextSetRotation(text, 30.0);

The type fonts WindowsBitmapfont is a serious disadvantage: it only supports ANSI encoding. This means that in one application cannot use the symbols of several different alphabets. To solve this problem in the Xtreme3D was added support for the library and FreeType UTF-8 encoding, which allows you to display any characters without restrictions. Using the FreeType you can download ttf-fonts from the files, which is very convenient - you do not have to worry about whether the desired font on the user's system: all the necessary fonts may have shipped with the game.

The creation of the font and the on-screen text using the FreeType looks as follows:

Font = TTFontCreate('data/font.ttf', 14);
Text = HUDTextCreate(font, 'Hello, World!', the global.front);

The text string you pass to the HUDTextCreate, must be encoded in UTF-8. Unfortunately, the Game Maker 8 does not support UTF-8 in the built-in editor code, therefore the text containing the symbols of national alphabets should either download the file from the function of the TextReador convert the TextConvertANSIToUTF8.
To use the TTFontCreate place in the folder with the game of the freetype library.dll (look for it in the SDK).