Importing Vector Images

Here you can find information on importing vector based images and animations into GameMaker: Studio.

GameMaker: Studio has limited support for vector sprites. Generally all sprites in GameMaker use bitmaps which, while flexible in terms of content, place limitations on both the size and number of frames possible in a sprite before memory usage can become prohibitive. Vector sprites work around these limitations by storing and drawing their contents differently - instead of a grid of pixels, which can become blocky or fuzzy when scaled, they are drawn as triangles which can be scaled up without losing definition, as illustrated in the image below:

To help you visualise how this is done, the image below is of the same vector Fireman sprite only now we can see the polygons that are used to make the image within GameMaker: Studio:

However, nothing is ever for free when it comes to programming games, and the tradeoff here with vector sprites is that they are more expensive to draw than bitmap sprites and this speed difference increases as the complexity of the animation being imported increases. Also, their memory usage is affected by their visual complexity, unlike bitmap sprites. Baring that in mind, they do make it possible to add large animated graphics in ways that would be impossible using traditional bitmapped sprites.

On the flipside of the performance equation, because vector sprites only draw the pixels absolutely required (unlike bitmap sprites which also "draw" the empty space around the image) they can be cheaper from a GPU perspective. Also, in general vector sprites are much smaller than their bitmap equivalents - for the fireman example above the sizes of the various sprite types are as follows:

Bitmap at 70x68 = 4x70x68 bytes x 12 frames = 223k
Vector = 54k

If you quadruple the resolution of the sprite:

Bitmap at 280x272 = 4x280x272 bytes x 12 frames = 3570k
Vector = 54k

So as you can see a lot of memory can potentially be saved by using vector sprites, and we still have a lot of potential for future space savings.

How To Import Vector Images

Currently GameMaker: Studio can only import vector images from SWF format files, and the way of importing them into the program is almost identical to that for adding a normal bitmap image. To add a vector sprite, create a new sprite, which will bring up the standard Load Sprite dialogue, but make sure that you have selected *.swf from the file filter at the bottom.

Hitting the "load" button will add the vector image or animation to the resource tree, with a progress bar being shown as the file is processed. Note that, depending on the complexity of the file, this can take a while (up to a minute for more complex animations). When processing has finished you'll be returned to the sprite properties dialogue, which will now look like this:

As you can see it looks like the normal sprite dialogue, with the first frame of the vector file shown in the image preview window on the right. There are a couple of changes from a normal sprite dialogue though. Firstly, the Edit Sprite button has gone since there aren't any bitmaps to edit in this sort of sprite, and secondly, a new Show Sprite button has been added. This button will open the vector file in whatever application is associated with it. This would normally default to your web browser, but if you do not have a program associated with the file, then nothing will happen and as the button is disabled (you can resolve this by opening Windows Explorer and right-clicking on a vector file, then using "open with" to choose the program to associate with these files). You can also associate a viewer for these sprites in the Editor Preferences within GameMaker: Studio and the Show Sprite button will open that instead of the default viewer.

NOTE: How the image looks in your chosen preview editor will not be the same as how it looks in your game, nor how it looks in the preview window of the sprite editor. The vector image will be imported at the size it was created at, which is not necessarily the size that the preview is shown at (browsers will normally scale the image to fit, for example).

You can also set the quality of the vector sprite when drawn. This will simply reduce or increase the number of triangles used to generate the sprite, with the default quality value of 50 being sufficient normally for most games, however you should experiment with this value if you are using extreme scaling, or are having performance issues. From this point the other parts of the editor should function the same as they do for bitmap sprites.

Important Things To Note

There are a number of things that you should be aware of when importing vector sprites, with the most important being that some of the sprite drawing and sprite management functions are not supported for technical reasons, particularly those draw functions that draw only part of a sprite, or that "skew" the position in some way (see the individual draw_sprite_*() functions for exact details of which). However the basic sprite drawing functions are fully supported as are the built in sprite variables. You can also set different anti-aliasing (AA) values for the SWF sprites being drawn using the functions found here: Drawing Sprites and Backgrounds.

You should also be aware of the following:

Back: More About Sprites
Next: Editing Sprites
© Copyright YoYo Games Ltd. 2018 All Rights Reserved