I want to make a separate file for my map, like i have a separate file for my player. It works well for my player but when i do it with my map, for some reason i don’t know, my player can’t move when it starts. Here’s what i have in my map.cs file:
private int tileX;
private int tileY;
private int x;
private int y;
public Mapa(int pTileX, int pTileY, int pX, int pY)
tileX = pTileX;
tileY = pTileY;
x = pX;
y = pY;
public void draw(SpriteBatch spriteBatch, Texture2D backGroundFloor)
for (int position = 0; position <= 2560; position += 32)
for (int positionY = 0; positionY <= 1440; positionY += 32)
spriteBatch.Draw(backGroundFloor, new Rectangle(position, positionY, 32, 32), Color.White);
That’s because in the working code you posted, you’re reusing the same spriteBatch you use to draw the player, the one that had a camera field passed into its Begin() call, without ending and beginning the spriteBatch, whereas in the Mapa class, you call Begin again, but this time with no camera field passed in. The result is that the map is always drawn starting from the upper-left corner of the screen, and the player doesn’t appear to be moving, even though the player’s position values actually were being changed.
You shouldn’t need to call spriteBatch.Begin in the map’s draw method. Just begin the spriteBatch, draw the map, draw the player, and then end the spriteBatch.
To reiterate, in order to get the same behavior with the Mapa class, you’ll need to move the mapa.draw(_spriteBatch, backGroundFloor); call to be after the _spriteBatch.Begin(this.camera); line, and then delete the spriteBatch Begin and End lines in the Mapa draw method.
Lol this seems like such an stupid thing, i actually did it before and i’ve got an error, idk what i did probably messed something in my code… it works now. Sorry for the silly question and thank you so much for your attention, i really appreciate it!
Yea this is where I land. I first learned this style with m_ in C++ coding but have since switched over to just using _ for class members instead. Just a style preference, and at this point in my career I’m so over style discussions between two literate and educated developers who are both capable of understanding different styles. Keep it consistent within a file, move the heck on.