Importing sprites into GameMaker is a straightforward process. Here’s how you can do it:
Open your GameMaker Project: Launch GameMaker Studio and open the project where you want to import your sprite.
Navigate to the Sprites Resource: In the 'Resources' tree, find the 'Sprites' section.
Create or Import a Sprite: Right-click on 'Sprites' and choose 'Create Sprite' to make a new one, or 'Import' to add an existing image file as a sprite.
If importing, a dialog will appear allowing you to browse your computer for image files. GameMaker supports various formats such as
.gif, etc. Select your desired image and click 'Open'.
Edit Sprite (Optional): Once imported, you can double-click the sprite to open the sprite editor, where you can modify it further. You can change its size, add frames for animation, or adjust its collision mask.
Naming Your Sprite: It’s a good practice to rename your sprite to something meaningful within the sprite properties. This will help you easily identify it in your code and within the resource tree.
Here's an example of creating a sprite through GameMaker Language (GML), GameMaker's scripting language:
In this GML example,
sprite_create_from_file is used to create a sprite from an external file during runtime. The function takes the file path, the number of subimages, whether to remove the background, and the origin x/y coordinates.
sprite_set_name is then used to rename the newly created sprite.
Remember that if you're working with animations, each frame of the animation should be imported as a separate subimage within the same sprite resource.
When importing multiple files at once, GameMaker can automatically arrange them into a single sprite with multiple subimages, which is perfect for animations where each file represents a single frame. For an animated sprite, simply select all the corresponding images during the import process.
Following these steps will ensure that your sprites are ready to be used in your GameMaker projects.