GameMaker: Studio

GameMaker: Studio

View Stats:
Sky Render Apr 8, 2017 @ 11:12am
Making "layered" sprites: how to?
So I'm interested in making a player appearance customization system, and the simplest way to get that to work that I can tell would be to basically assemble the player sprite in layers. Only problem: I have no idea how to proceed, as the basic toolset does not make it obvious how one would do this. Having the player be a dozen independent objects moving in unison via parent/child settings sounds like a horrible idea to me, but it looks like that may be my only choice if there isn't a better way to pull this off.
< >
Showing 1-2 of 2 comments
By default you assign an object a single sprite when you make it. However, you can use an objects draw event to draw any other sprites you might want if you don't want to create seperate objects for the layered pieces.

For example, if I made an army tank and wanted to add a gun turret to it. I could just do this in the draw event...
draw_self(); draw_sprite(spr_turret, 0, x, y);

Things are drawn in the order (layered) based on what comes first.

'draw_self();' tells the object to draw the sprite it was originally assigned. Anytime you make your own draw event for an object it overrides it drawing itself by default so you have to tell it to draw when you want it to.

'draw_sprite(spr_turret, 0, x, y);' will tell it to draw the sprite of my turret. The 0 is what frame you want the sprite you're drawing to show. In this code snippet I'm assuming there is only a single frame so I draw it at 0. The x / y is the location on the screen to draw it at. Since I just put 'x' and 'y' its using the objects x / y origin point so in this case I'm assuming the origin of the tank player object is where the turret would attach. By using 'draw_sprite' I'm also assuming the rotation of the object won't ever change.


If I wanted the turret to rotate I'd use 'draw_sprite_ext' since that allows you to specify an angle to have the sprite facing. If my tank objects origin point isn't where I want the turret to attach then I'd have to use the 'lengthdir_x' and 'lengthdir_y' functions to calculate the position to place the turret.


Alternatively, there isn't much stopping you from just making another object to be the attached piece and then in its step event assigning its x / y position to the location where you want it to be attached to. Unless your game is super demanding on performance, such as having hundreds of objects on screen each with other objects "attached" to them and some really crazy collision code, it really shouldn't noticeably affect your game.
Sky Render Apr 8, 2017 @ 2:11pm 
Okay, so the engine is actually smarter than I gave it credit. I'm used to travesties like the RPG Maker series, particularly pre-XP, where you had to kludge everything.
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Apr 8, 2017 @ 11:12am
Posts: 2