im trying to make Space Invaders as a first learning project. and got to the point where i have a moving player, some enemies and a bullet to shoot. however, the bullet’s hitbox does not align with its texture.
i dont know what to do with it anymore. and ive come here with good hopes that anyone here can help me
So spritebatch.draw has a number of different overloads.
One of them takes a rectangle for a location to draw. Another one takes a vector2 (its recommended to use a vector for more smooth precise drawing because it uses floats)
One of the overloads for drawing with a vector2 is the origin of the sprite your drawing as a vector. Try and set the origin of the sprite to a vector of half the size of your sprite
I think what boot is saying is, the Hitbox rectangle is relative to where the GameObject is.
So if your Hitbox is 32x32 then it’s going to be:
X = GameObject.X
Y = GameObject.Y
Width = 32 Height= 32
This means in your Update() you need to keep updating the Hitbox (X,Y) as each GameObject moves.
I can’t see from the code you posted whether you are doing that or not (it should be in the Update()).
It looks like you are drawing each bullet into its own texture at position 0,0 (guessing).
But what’s important is the location where you draw the textures later on the game screen.
This location is the topleft (x,y) of your hitbox.