Can U Use A Static Background Instead Of Sprite Game Maker Studio 2
sprite_add
With this function you lot can add together an image as a sprite, loading it from an external source where the image file to be loaded should always be in either *.png, *.gif, *.jpg/jpeg or *.json format (*json files are used for loading skeleton animation sprites made with Spine). The function returns the new sprite index which must then be used in all further code that relates to the sprite. If yous use this function with HTML5 or are getting an epitome from a URL, this function will also generate an Image Loaded asynchronous event. Meet this page for more data.
All images that are to be turned into blithe sprites - except for *.gif (see below) - should take a "strip" format (see the image below) and it will be carve up into the number of sub-images specified following the rule sprite width = strip width / sub images.
Every bit you lot tin can see in the to a higher place image, the sprite has been placed on a dark purple groundwork, and this can be removed by setting the "removeback" argument to true. This works by checking the lesser left pixel of the sprite for the color there and so uses that as the colour to be removed. For example, in the above image, if we had the bottom left pixel colour every bit green, all the green parts of the sprite would have been removed and the rest of the purple groundwork ignored.
If you choose the "removeback" option, you may also want GameMaker to smooth the edges of the sprite by setting the "smooth" argument to true. All this does is create a semi-transparent edge around the edges of the sprite later on it has had its background removed.
Finally you can also specify the x and y origin for the sprite. This is the point where the sprite is "stock-still" onto the instance that uses it, and is ever calculated as relative to the 0,0 top left corner of one sprite sub-paradigm. So, for case, a sprite that is 32 x 32 pixels with these values set to (xvi,16) volition have its origin in the heart.
If you lot are calculation a *.gif format image, so you only need to specify the filename and image number (which should exist i for the showtime frame) and can leave all the other arguments as 0, noting that only the first image of the GIF volition exist loaded. For *.json sprites, the paradigm number should be 1, and the "removeback" and "smooth" settings will be ignored.
Past default all new sprites have their bounding boxes calculated automatically (the exact bounding box will depend on the size and transparency of the sprite), all the same you may wish to customise this, in which instance you should besides use the office sprite_collision_mask().
Information technology should be noted that the memory used when adding a sprite in this manner will be larger than you may wait. This is because GameMaker will store the sprite as a texture folio and it will too be stored in GPU memory, so the total retentivity volition be larger than would be expected for an image file of the aforementioned sprite.
NOTE: When you load a sprite into GameMaker y'all must remember to remove information technology again (with sprite_delete()) when no longer needed, otherwise there is risk of a memory leak which will wearisome down and eventually crash your game.
Note: On iOS, if y'all are loading an included file from a folder, ie: with a path something like " Backgrounds/background1.png ", you practise NOT need to include the binder as part of the path and merely supplying the file proper noun is sufficient. On all other platforms you must supply the folder(southward) every bit part of the path to the file.
NOTE: On HTML5, if you are loading a sprite from a secure server y'all may demand to set the cross-origin type and apply a relative path instead of an absolute path. See http_set_request_crossorigin() for more details.
Syntax:
sprite_add(fname, imgnumb, removeback, smooth, xorig, yorig);
Argument | Type | Clarification |
---|---|---|
fname | String | The proper noun (a cord file path) of the file to add. |
imgnum | Real | Use to indicate the number of sub-images (i for a single prototype or for a *.gif). |
removeback | Boolean | Indicates whether to make all pixels with the background color (left-bottom pixel) transparent. |
polish | Boolean | Indicates whether to smooth the edges if transparent. |
xorig | Existent | Indicate the x position of the origin in the sprite. |
yorig | Real | Indicate the y position of the origin in the sprite. |
Returns:
Sprite Asset
Instance:
spr = sprite_add("player_5.png", xvi, true, true, 0, 0);
The in a higher place lawmaking loads a sprite into the game and stores its index in the variable "spr".
Can U Use A Static Background Instead Of Sprite Game Maker Studio 2,
Source: https://manual.yoyogames.com/GameMaker_Language/GML_Reference/Asset_Management/Sprites/Sprite_Manipulation/sprite_add.htm
Posted by: ingramshament.blogspot.com
0 Response to "Can U Use A Static Background Instead Of Sprite Game Maker Studio 2"
Post a Comment