Page 1 of 1

[SOLVED] SDL loading images problem

Posted: Mon May 17, 2010 4:19 pm
by mary
My program is working fine, but when I try to add another image with SDL_Surface *image; the program clips a separate image incorrectly, but it only does 1 of the clips wrong and it is in the middle of the clipping, if I take away the new SDL_Surface *image; it works perfectly.

Re: SDL loading images problem

Posted: Mon May 17, 2010 4:22 pm
by eatcomics
Code pl0x? kthxbai

Re: SDL loading images problem

Posted: Mon May 17, 2010 5:20 pm
by mary
I have no idea what code would even be relevant, I have two pictures of that it clips into 6, and on the 5th clip it generates the whole picture of the other, and can shrink and grow with the motion of the mouse, even though I don't have any mouse movement in this project, and I dunno why any code would not let me declare any more variables, its just a weird glitch.

EDIT: also when I click the mouse the extra image disappears, and when the mouse is not in the screen.

Re: SDL loading images problem

Posted: Mon May 17, 2010 5:40 pm
by eatcomics
... Wow, see just show us your clipping code, your input code and your drawing code... If you don't know what's relevant post it all, and maybe try and give a clue... because you telling me hasn't helped me much

Ok so like your clipping a sprite sheet and its not working right... Lemme use my powers of divination to figure out what's wrong

Re: SDL loading images problem

Posted: Tue May 18, 2010 9:37 am
by mary
SOLVED!

Re: [SOLVED] SDL loading images problem

Posted: Tue May 18, 2010 4:20 pm
by eatcomics
Good :D sorry if that post up there was a little too harsh, I was quite tired when I wrote that...

Re: [SOLVED] SDL loading images problem

Posted: Tue May 18, 2010 4:55 pm
by mary
the post wasn't too harsh, made me go back and edit how I was drawing the tiles, I had no clue what could be messing it up, seemed like clipping but couldn't figure out why.
I do not what the problem was, but I had an array for clipping, and 1-6 were set to something, but I ignored 0. so I went back and made the array 1 shorter and set 0 to a variable. I didn't think it would be a problem if I had the first cell set to anything. How the program worked is it clipped according to the map, then I changed it to if the map equals 1 then set it to the 2nd clip. Why did it change the size of the clip on that particular piece is beyond me, and that is what I was trying to figure out, and why would declaring make the glitch happen, well that is beyond me too, the good news is I fixed it, at least I think I did, have not had a problem since.

Re: [SOLVED] SDL loading images problem

Posted: Tue May 18, 2010 8:18 pm
by eatcomics
yeah arrays start at 0, so you gotta account for that, can really mess up your clipping

see an array say
array[10];

would actually be accessed by the numbers 0-9, because 0 counts as a number... I don't know if that exactly was your problem, but that's what it sounds like to me

Re: [SOLVED] SDL loading images problem

Posted: Tue May 18, 2010 8:47 pm
by mary
I understand that an array of 10 is numbered 0 - 9, but what I was attempting to do was something like this, looking at the code I was setting the array 0 - 6

Code: Select all

tile[6];

for (int i=1; int i<7; i++) 
{
	tile[i-1].x = (i)*PIECE_SIZE;
	tile[i-1].y = 0;
	tile[i-1].w = PIECE_SIZE;
	tile[i-1].h = PIECE_SIZE;
}
I would then load the function which calls 2 for loops which go through the map I made and draws the surface of the selected tile, every time the loop went through the second loop it would add 1 to the counter. This code is based off of memory so it may not be accurate.
draw_surface (grass, PIECE_SIZE*i, PIECE_SIZE*j,tile[selectedPiece[counter]]);
draw_surface (grass, PIECE_SIZE*i, PIECE_SIZE*j,tile[-1+(selectedPiece[counter])]);

Re: [SOLVED] SDL loading images problem

Posted: Tue May 18, 2010 9:54 pm
by eatcomics
yep then that was your problem, the array only goes to 5 :P
so you're accessing some random memory for something else... that's why you get problems