Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Loading a sprite from a external spritesheet (GM6)???


Recommended Posts

Even in Game Maker official forums, I hadn't found any coding for this.

This could help many, many, many people to load external animated sprites from single spritesheets, tilesets or strips (especially really big ones), instead of keeping separated animated gifs to be loaded (that's not secure at all).

But I couldn't find any method in GML that loads each image part as a single subimage for a sprite.

Anyone have any idea how it works?

Link to comment
Share on other sites

sprite_add(fname,imgnumb,precise,transparent,smooth,preload,xorig,yorig)

Adds the image stored in the file fname to the set of sprite resources. Many different image file types can be dealt with. When the image is not a gif image it can be a strip containing a number of subimages for the sprite next to each other. Use imgnumb to indicate their number (1 for a single image).

Basically, it means you can load animated sprites from a sheet, but each frame of the sheet needs to be stored horizontally (like GM exports them) and each frame to have the same box size. Upon the img number entered, GM will automatically calculate the size of each box frame

Let's say we have a sprite sheet wich contains three frames. Each frame is 64x64 in size, so the resulting sheet size is 192x64. If you pass 3 to img number, it'll calculate that each frame is horizontal width / number of frames, in other words, 192 / 3 = 64.

If you don't like it this way, you can always make your own loading function through surfaces and stuff.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...