0 Members and 4 Guests are viewing this topic.
memblock = new char [size]; memblock[0] = x; memblock[1] = y; for(int i = 0; i<size; i++) { memblock[i+2] = *(array + i); }
for(int i = 0; i<size; i++) { memblock[i+2] = *(array + i); }
if (Input.IsMouseButtonDown(sf::Mouse::Left) || Input.IsMouseButtonDown(sf::Mouse::Right)) { sf::Vector2f MousePos=App.ConvertCoords(Input.GetMouseX(), Input.GetMouseY()); x=MousePos.x/64; y=MousePos.y/64; if (x<0) x=0; if (y<0) y=0; if (x>xx-1) x=xx-1; if (y>yy-1) y=yy-1; if (Input.IsMouseButtonDown(sf::Mouse::Left)) *(array + x + (x * y))=selectedimage; else if (Input.IsMouseButtonDown(sf::Mouse::Right)) *(array + x + (x * y))=selectedimage2; }
// Draw stuff on main window for (y=0; y<yy; y++) { for (x=0; x<xx; x++) { if (*(array + x + (x * y))==-1) continue; imgs[*(array + x + (x * y))].SetPosition(x*64, y*64); App.Draw(imgs[*(array + x + (x * y))]); } } // Draw stuff on the image list for (a=0; a<numofimgs; a++) { imgs[a].SetPosition(0, a*64); App2.Draw(imgs[a]); } Selection.SetPosition(0,64*selectedimage); App2.Draw(Selection); Selection2.SetPosition(0,64*selectedimage2); App2.Draw(Selection2); // Update the window App.Display(); App2.Display(); }
*(array + x + (x * y))
*(array + x + (x * yy))
memblock[x * y + 2] and memblock[x * y + 3] are written to when they shouldn't be.
Code: [Select]*(array + x + (x * y))should beCode: [Select]*(array + x + (x * yy))
char * tiles; tiles = new char [xx * yy]; // this array will store the image number for each tile char * array = &tiles[0];
char * array; array = new char [xx * yy]; // this array will store the image number for each tile
"*(array + x + (x * y))" in the initializing part needs to be changed to "*(array + x + (x * yy))"
I thought char was 1 byte, int was 2, and long was 4
chars work for small ints from -127 - 128 or 0 - 255 no ints go above or below that, or they shouldn't.