Hi all guys, i’m new with videogame and java videogame, i try to make a platform 2D and i don’t know how can add a weapon to my player, i have a sprite for weapon and a sprite for player. Someone can help me?
I think your question needs further clarification before any meaningful advice can be given.
Ok i try to explain.
I’ve a player sprite with animations, WALKING, IDLE, JUMPING ecc.
The sprites are only with characters without nothing in his hands, now i create a shooting function and i want that when my char fire an enemy in the hand must have a gun, gun is another sprite outside player’s sprite. I want something overlap a kind of child of a player object.
Alright, so you can either have a class called Gun that stores the location of the gun and renders it and set its position to the player plus the offset. Or you can store that same data in your Player class and draw it from there. The gun’s position would be the player’s position plus the offset.
Example:
gun.draw(playerPosition.x + offsetX, playerPosition.y + offsetY);