oh sure, you also have to keep in mind that there is scrolling...
ahcfan allready explained it but I'll just be more detailed
The camera position gives you an offset of where you are, calculated from 0 you are at position camera, then you add the mouse Vector
brings back memories from Vector Calculation in school.
in vector additions:
0 + camera = top left of the view;
camera + mouse = the tile;
1 2 3 4 5
|
Vector2<int> position;
position.x = (mouseX + camera.x) / tile::TILESIZE_X;
position.y = (mouseY + camera.y) / tile::TILESIZE_Y;
tileMap[position.x][position.y] = WALL;
|
EDIT:
Suggestion for Improvement:
why do you not use a Vector2<int> to store the Tilesize and the Mouse position?
when doing this and overloading some operators you could write it like this:
position = (mouse + camera)/tile::Tilesize;
And since you probably need to do more vector additions, i think it would be a good idea :)
Also: it would be a good exercise ;)