Archived

This topic is now archived and is closed to further replies.

For loops to set up an array of SDL_Rects

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, here I am yet again... I'm wanting to set up a 2D array of SDL_Rects as the viewing area in my game(with a tile in each position) Here's some of the code I'm trying: int setrectcord(SDL_Rect rect, int x, int y){ rect.x = x; rect.y = y; } Then later... SDL_Rect *screencord[15][9]; for(int xval = 0; xval < 14; xval++){ for(int yval = 0; yval < 8; yval++){ setrectcord(*screencord[xval][yval], (xval * 32), (yval * 32)); } } The point is to have an SDL_Rect for every displayed tile position on the screen,(every 32 pixels) but when I try to draw anything to one of these positions, I get a segmentation fault...do keep in mind, though, I'm a terrible programmer.(which you could most likely tell from the code) P.S. I've probly forgotten some important thing I need to mention... [edited by - Klarh on April 23, 2004 10:01:51 AM]

Share this post


Link to post
Share on other sites
i''ll just blow your whole idea apart and spare you the trouble: you shouldn''t have to have an sdl rect for every tile. If your tiles are all the same size, it''s only a simple calculation to figure out it''s boundries. for instance, tile #6 starts at 6*32 and ends at 7*32

Share this post


Link to post
Share on other sites
Hmm...Okay, so I should make a handy dandy function the takes care of all the coords mess for me? Thanks, I was really stumped on that one

Share this post


Link to post
Share on other sites
basically, yeah. You would just be making a 2D array of tiles for a tile engine there. You would display them based on their position in the array and their size. (see first comment). That way, you can change tile sizes and it will still display nicely.

Share this post


Link to post
Share on other sites