redraw map - I don't find the mistake
in
Programming Questions
•
6 months ago
Hi,
I draw a map (for debugging reasons it now has a color gradient).
When I try to redraw a part of it, the picture is wrong. I don't find my mistake.
Maybe I am blind ...
I generate the map like this:
- void initializeMap() {
- for (int x=0;x<Size;x++) {
- for (int y=0;y<Size;y++) {
- if ((x % 20) == 0 || (y % 20) == 0) map[x][y] = int(50 + x/2.5) ;
- else map[x][y] = 0;
- }
- }
- }
I draw the map like this (size is the size of the array/map - mapX and mapY are the offset on the screen):
- void drawMap() {
- if (newcoord == true) {
- for (int x=0;x<Size;x++) {
- for (int y=0;y<Size;y++) {
- stroke(map[x][y]);
- point(x+mapX, y+mapY);
- }
- }
- }
- }
I redraw like this (just a simplified test for now - the usecase will be more complicated):
The only change to the draw map (which works) is that I don't query the whole array.
"
for (int x=100" instead of
"
for (int x=0"
- void deleteRobot() {
- for (int x=100;x<Size;x++) {
- for (int y=0;y<Size;y++) {
- stroke(map[x][y]);
- point(x+mapX, y+mapY);
- }
- }
- }
The correct map:
Wrong ater partial redraw:
I hope you see the error. Must be something stupid.
Thanks
Robert
1