So I’m making a 2D top down RPG with LWJGL and I wanted the player to be able to carry some kind of armor as well as a weapon, and have those items affect what the player sprite looks like. But I ran into a problem. If I have the character sprite, that has lets say 8 images (2 for walking left, 2 for walk right, 2 for walking up, and 2 for walking down), do I have to create 8 more for every possible combination of weapons and armor? How is THAT efficient? I know their must be another way…
It’s simple. If you have lets say 10 different hats, you could create 10 head sprites facing forward, 10 facing left, 10 facing right and 10 facing backwards. You could do the same for the body, legs, feet and hands.
Modular sprites.
Split your player sprites into seperate parts, Legs, Torso, Arms, Head.
Afaik this is the only way.
hmm well in my game I have a player who can obtain different fire arms. I just draw that new fire arm’s sprite on top of the player. So maybe you could do that with the ammo. You could go about it like this:
Player Class
//Basic class stuff
public void render(Graphics g) {
g.drawImage(sprite, x, y, null);
}
public void tick() {
x+=velX;
y+=velY;
}
//Other basic class stuff
Gun class
//Class Stuff
public void render(Graphics g) {
g.drawImage(sprite, Player.x - 16, Player.y + 16, null); //The subtraction and addition would be positioning on the player
}
//Other class stuff
Hope this helps!
all you need is 4 images then just rotate them to your needs do same with weapons / hats / armor
rotation and drawing it ontop is probably the easiest way. you can do 8 different sprites however you will have memory issues if you have thousands of items.