Negative X-coords (objects off-screen)

Hello, I’ve never used mailing lists before, so I sure hope I’m doing this
right! I’m also fairly new to SDL, so I hope this is not a bad question. I
have had trouble in searching for the answer so far:

How does one prevent an SDL_Rect from resetting to zero every time a negative
x-coord is put in? (e.g. scrolling trees from right to left to mimick moving,
and they stop moving once they hit zero X). I got around this by storing the
values in an array and then feeding them into SDL_Rect just before they’re
drawn, but I think there must be a better way?

Thanks :slight_smile:

ptuckey wrote:

Hello, I’ve never used mailing lists before, so I sure hope I’m doing this
right! I’m also fairly new to SDL, so I hope this is not a bad question. I
have had trouble in searching for the answer so far:

How does one prevent an SDL_Rect from resetting to zero every time a negative
x-coord is put in? (e.g. scrolling trees from right to left to mimick moving,
and they stop moving once they hit zero X). I got around this by storing the
values in an array and then feeding them into SDL_Rect just before they’re
drawn, but I think there must be a better way?

I had the same “problem” and then I read docs more carefully.

SDL_BlitSurface:
“The final blit rectangle is saved in dstrect after all clipping is
performed (srcrect is not modified).”

So I guess you either set the coords each time before drawing, or you
alter the SDL source code ;)–
Milan Babuskov
http://fbexport.sourceforge.net

[…]

How does one prevent an SDL_Rect from resetting to zero every
time a negative x-coord is put in? (e.g. scrolling trees from
right to left to mimick moving, and they stop moving once they
hit zero X). I got around this by storing the values in an array
and then feeding them into SDL_Rect just before they’re drawn,
but I think there must be a better way?

I had the same “problem” and then I read docs more carefully.

SDL_BlitSurface:
“The final blit rectangle is saved in dstrect after all clipping is
performed (srcrect is not modified).”

So I guess you either set the coords each time before drawing, or
you alter the SDL source code :wink:

Well, both of you seem to be suffering from a side effect of a rather
common mistake: You’re building the SDL API into your applications,
instead of having your applications use SDL to do I/O.

What I’m saying is, don’t use SDL_Rect structs and whatnot all over
the place in your code. Those are part of SDL and belong in the low
level code that talks to SDL.

You’ll get my point when it’s time to port to another API (say,
OpenGL), or a new major version of SDL. :wink:

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 15 September 2003 10.15, Milan Babuskov wrote:

David Olofson wrote:

Well, both of you seem to be suffering from a side effect of a rather
common mistake: You’re building the SDL API into your applications,
instead of having your applications use SDL to do I/O.

What I’m saying is, don’t use SDL_Rect structs and whatnot all over

But we have to use it at least once, right?

You’ll get my point when it’s time to port to another API (say,
OpenGL), or a new major version of SDL. :wink:

Well, not everything is as it seems. :wink:
I ported my game (Njam) in about ten days from DirectX to SDL… without
problems. (It’s probably because SDL is great !). Most of the job was
to give correct values to search&replace.

Regards,–
Milan Babuskov
http://njam.sourceforge.net

David Olofson wrote:

Well, both of you seem to be suffering from a side effect of a
rather common mistake: You’re building the SDL API into your
applications, instead of having your applications use SDL to do
I/O.

What I’m saying is, don’t use SDL_Rect structs and whatnot all
over

But we have to use it at least once, right?

Well, it sure helps, as blitting full surfaces to (0,0) gets pretty
boring after a while. :wink:

Anyway, I’ve made similar mistakes myself more than once, when using
SDL_Rect in conjunction with loops. As a result, I’ve pretty much
stopped using SDL_Rect for anything but passing arguments.

You’ll get my point when it’s time to port to another API (say,
OpenGL), or a new major version of SDL. :wink:

Well, not everything is as it seems. :wink:
I ported my game (Njam) in about ten days from DirectX to SDL…
without problems. (It’s probably because SDL is great !). Most
of the job was to give correct values to search&replace.

Sounds like you write nice code - so now I’m only worried about
ptuckey, who was talking about scrolling trees and stuff, as if the
SDL_Rect was part of the game logic… :wink:

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 15 September 2003 14.55, Milan Babuskov wrote:

I’ve been trying to figure out how to reply to a message from the mailing
list…this is sort of a test message, and if it works then I’ll re-write what
I tried sending before :slight_smile: …if this does work, can someone please direct me
to a page that will tell me how to use this list properly?

thanks, -Fizban aka ptuckey**********************

Hello, I’ve never used mailing lists before, so I sure hope I’m doing this
right! I’m also fairly new to SDL, so I hope this is not a bad question. I
have had trouble in searching for the answer so far:

How does one prevent an SDL_Rect from resetting to zero every time a negative
x-coord is put in? (e.g. scrolling trees from right to left to mimick moving,
and they stop moving once they hit zero X). I got around this by storing the
values in an array and then feeding them into SDL_Rect just before they’re
drawn, but I think there must be a better way?

Thanks :slight_smile:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl