[SDL] SDL-CVS mailing list

Sam Lantinga slouken at devolution.com
Sun Jan 19 15:10:00 PST 2003

On Sun, 5 Jan 2003, M. Egmond wrote:

> At 2003-01-03 21:54, you wrote:
> >#define UP 1
> >#define RIGTH 2
> RIGTH should probably be RIGHT. It's not a problem since you make the same 
> spelling mistake in the code, but it might look better if you correct it.
My mistake, im bad with those words.
> I would opt for using more parameters instead of global variables here, but 
> that may be more of a style issue. However, often global variables obscure 
> dataflow. For example my choice might be something like:
>    int loadimg(SDL_Surface *screen, SDL_Surface **image1return, SDL_Surface 
> **image2return);
> and then return an error code from the function. If you don't do error 
> checking (for example because it's meant to be a simple example) then you 
> can simply 'return 0' at the end to indicate it always succeeds (assuming 0 
> is your choice to return OK, and non-zero are error codes). Anyway, I 
> already said this is more a style issue, so I will shut up about it now :-)
Besides, Im also bad with parameters in C. Ill take note of that.

> Ah, I like printing errors to stderr instead of stdout. Good! :-)
> [snip]
> Not sure why you need KeyRepeat. Your code sets 'direc' on a keypress, but 
> never resets it, so a keyrepeat would simply overwrite direc with the same 
> value. If you want to allow multiple directions to be pressed at the same 
> time, it might be useful.
I took it from SDL examples. Neither I knew if it was really useful in so 
small example.

> Also, because you don't reset 'direc' when you stop pressing a key, the 
> direc flag will remain set, and your 'object' will keep travelling in the 
> direction that was pressed last.
Ah, what stupid! I knew i was missing something.

> [snip]
> >  //Ahora movemos la imagen de acuerdo a la direccion
> >  switch (direc){
> >         case UP:
> >            if (area.y>1) area.y--;
> This code is not timed, and will execute each loop. This means that if you 
> have a very fast videocard (or refresh rate) the 'object' will travel a lot 
> faster than on a slower machine/refresh rate. You might want to do 
> something like:
Yes, but fixed framerate is planned maybe for a "future" article.
> Hope this helps!
It helps a lot, thanks.

Roger D. Vargas         | El sistema se apagara en 5 segundos.
ICQ: 117641572          | Salvese el que pueda!
Linux User: 180787      |

More information about the SDL mailing list