SOLVED How should i approach drawing sprites from my player?

Hello everyone!
I've been wondering about what method should i use to draw my player weapon when it attacks, since i have the weapon sprite separate from the player actual sprite. The reason for this is that i want to be able to change the weapon sprite in a easier way and independently from the player actual sprite set.

I managed to make it work by creating an object, instancing and giving it the sprites i wanted thru code in my player step event, inside it's attack state machine.
Tho this method works, i've been thinking if there are other methods that can be more optimal for this purpose, like, i'm thinking of drawing the sprites right away from draw event, tho i don't know if this would be better or worse.

Any advices?
Thanks in advance 🙏👊
 

NightFrost

Member
You didn't mention what kind of game that is, but I assume 2D style with top-down or side view. Separate weapon instance is one way to go about it. To give a classic example done in GMS, Nuclear Throne seems to have its weapon equip in the same manner. This has many advantages, as you can create weapons without having to draw a new player to go along, and it can be separately rotated to point wherever. Games where your weapon never changes it frequently is incorporated to player sprite and the game just spawns hitboxes to confirm enemy damage. For example Hyper Light Drifter and Momodora appear to work this way.
 

kburkhart84

Firehammer Games
It will most likely be more efficient to just draw the weapon in the player object. However, it may not be better. In my case, my space shooter has 4 different weapons, each with two modes, making 8 different behaviors. Instead of having all that code in the player, I have a separate weapon controller which follows the player around. Then it controls which weapon is currently active, and spawns that separate object for each weapon, which then does its own thing as needed. I find this method works best for me. It allows the weapons to easily behave differently. It also allows me to add and remove things later if the need arises with very little change to anything that isn't the weapon itself. And each weapon is its own thing so they can't interfere with each other(since I never let more than one ever be active).
 
It will most likely be more efficient to just draw the weapon in the player object. However, it may not be better. In my case, my space shooter has 4 different weapons, each with two modes, making 8 different behaviors. Instead of having all that code in the player, I have a separate weapon controller which follows the player around. Then it controls which weapon is currently active, and spawns that separate object for each weapon, which then does its own thing as needed. I find this method works best for me. It allows the weapons to easily behave differently. It also allows me to add and remove things later if the need arises with very little change to anything that isn't the weapon itself. And each weapon is its own thing so they can't interfere with each other(since I never let more than one ever be active).
That actually brought some good light on the question man!
Tho i'm still prototyping the game, thinking ahead when having different weapons and stuff it would cluster lots of code inside the player which already has lots of code 😂
I'll most likely end up working with a controller for my weapons as well since there will be also guns with different behaviours.

Thanks a lot!
 
You didn't mention what kind of game that is, but I assume 2D style with top-down or side view. Separate weapon instance is one way to go about it. To give a classic example done in GMS, Nuclear Throne seems to have its weapon equip in the same manner. This has many advantages, as you can create weapons without having to draw a new player to go along, and it can be separately rotated to point wherever. Games where your weapon never changes it frequently is incorporated to player sprite and the game just spawns hitboxes to confirm enemy damage. For example Hyper Light Drifter and Momodora appear to work this way.
Yeah i was thinking about that, like, if my character only had a few weapons i wouldn't even draw the weapons separate from the actual attack sprites, it would be all one thing, but since my intentions is to actually work with more weapons for the same character i'll try it with the controller approach that kburkhart mentioned.

Many thanks for the help!!
 
Top