Sprite center game maker
We want asteroid to keep rotating throughout the game. So we have to add this action in Step event. Add Step event and use Execute Code action in the actions list. Here we are telling Game Maker to rotate the sprite by 5 degree. Since we used this code in Step event, it will keep rotating. Step event occurs continuously throughout the game. So the asteroid the will keep rotating. Finally you can also specify the x and y origin for the sprite. This is the point where the sprite is "fixed" onto the instance that uses it, and is always calculated as relative to the 0,0 top left corner of one sprite sub-image.
So, for example, a sprite that is 32 x 32 pixels with these values set to 16,16 will have its origin in the center. It should be noted that the memory used when adding a sprite in this way will be larger than you may expect. It is made up of six frames, or subimages.
GameMaker will play all frames in a sprite in sequence to give it animation. After a sprite is created, its property window will automatically open up.
It should look just like this:. Name : This is simply where you name your sprite. Make sure to give it a unique name. This is how the sprite will be referenced in the rest of your project, so make it consistent with the other resources. Collision Mask: There are two main components of every sprite. The visual representation of the sprite, and the space that the sprite occupies, called its Collision Mask.
Above the preview and frames window you have buttons to Play the animation, loop or ping-pong the animation when previewing. Beside these controls you can set the animation speed too. This value is based on the game frames a game frame is the time it takes to do one full game "loop" , so if you have, for example, a game fps frames per second of 60, and set the animation speed to 10, the animation will loop 6 times every second.
Setting this value here will affect how the animation will look in the game, and is not just for preview purposes. It's worth noting that you can set the animation to run either using frames per second, or frames per game frame, so choose carefully which one you use as 15 frames per second is not the same as 15 frames per game frame! In the middle of the editor you have a bar for defining the sprite origin and the collision mask we'll cover the collision mask in next page of the tutorial :.
By default it is the top left corner of the sprite but it is often more convenient to use the center it, or you may want some other point on the sprite. To change it, you can set the origin manually by clicking in the sprite preview image which will move the origin cross indicated in the image above to the point you clicked, or you can input different values for x and y in the corresponding boxes.
For fixed placement and to make things easier there is a drop down menu with a number of preset positions that you can choose from:. Note that you can even set an origin outside the area of sprite by using negative numbers for left and up or positive numbers larger than the sprite width and height for right and down , which can be very useful when dealing with objects that need to be drawn with composite sprites.
The final thing to talk about in this tutorial is the ability to set the collision mask for a sprite. The collision mask is the area that GameMaker Studio 2 uses to calculate when two instances with sprites assigned are in collision or not and trigger a Collision Event. Expanding the collision mask menu presents you with a number of options and gives a graphical representation of the current collision mask on the preview window:.
The mask will, by default, cover the whole image area, but you can click any of the mask "handles" marked in the image above and then drag to resize the mask.
0コメント