PDA

View Full Version : Problem with the SDL_BlitSurface function



ianatwork
11-12-2007, 03:44 PM
Hello,

I'm writing a side scrolling game and basically change the x-coordinate
of every sprite each frame. I used this technique in my previous
scroller called Cavern Fighter. Each sprite keeps having its
x-coordinate decremented until it disappears off the left side of the
screen and is no longer visible. In the game I'm working on at the
moment I'm using the same method but have come across a strange problem.
When my sprite gets to the left edge of the screen the x-coordinate
starts to go negative. Unfortunately the "SDL_BlitSurface" function
seems to convert the negative number back to a zero so the sprite never
scrolls off the screen. Although this creates in interesting effect as
all the sprites pile-up like some sort of sprite car crash, its not what
I want.

Has SDL changed to implement some sort of clipping ? Do I need to set a
flag ? The version of SDL.dll I am using is 1.2.12.0.

The function I am using is:

SDL_BlitSurface (Sprite.ImageSurface, Sprite.ImageDisplayRect,
m_SDLSurface, Sprite.ImageLocationRect) ;

When I call it with the Sprite.ImageLocationRect (with an "x" value of
-1), after the function exits the "x" holds a value of 0.

Hope someone can help or I'll have to rename my game "Cavern Crash" :roll:

Ian

KiCHY
11-12-2007, 05:23 PM
Hi Ian,

I assume you store sprite location in Sprite.ImageLocationRect variable and you do a "Sprite.ImageLocationRect.x = Sprite.ImageLocationRect.x - 1" to scroll left. This is a bad idea IMHO, because SDL_BlitSurface writes back its info into this variable. That's why there is a 0 in Sprite.ImageLocationRect.x. It writes back the clipped/visible region of this rectangle. 0 is leftmost position you can see on the screen...
(I hope I'm right, I didnt use SDL since years...)
Cheers,
KiCHY

ianatwork
11-12-2007, 05:28 PM
I think you have spotted the problem. I was thinking that I was passing in a copy of the sprites location but I'm actually giving it the "live" version. I'll check my code but I'm sure that's what I'm doing as it makes sense that its resetting the Sprites property :( Should be easy to fix. Thanks for that, I was left scratching my head on that one.

savage
11-12-2007, 06:04 PM
(I hope I'm right, I didnt use SDL since years...)
Cheers,
KiCHY

And the JEDI-SDL has not been the same since. Great to see you on here though.

Ian, your photo is a lot more feminine than I usually associate with people called Ian. I'll have to change my preconceived ideas about names.

ianatwork
12-12-2007, 08:43 AM
Ian, your photo is a lot more feminine than I usually associate with people called Ian. I'll have to change my preconceived ideas about names.

I can assure you that members of the PGD site would much rather look at an image of the lovely Sarah Beeny than a dodgy image of me :wink: . If anyone is really interested in what I look like you may just be able to see me as I flash past driving a rally prepped Subaru Impreza. There is a short video on my website (shameless plug :roll: )