Okay, I have been working on this piece of code for the past day or
so, and it STILL WON’T SCROLL!!!11
I am r3 at lly annoyed.? Does anyone know why when I press the up down,
left, and right keys, my map doesn’t scroll?
We may not be able to answer your question because it is possible
(probable, even) that none of us have used SDLMappy. One mistake
sometimes made is that every library with “SDL” in the name must have a
two-way relationship with the rest of SDL and the SDL community. In
fact, there are plenty of libraries that, while completely dependent
upon SDL, may only have been glanced at by, or never even seen by a
vast majority of the SDL community. A quick search shows that SDLMappy
has very limited presence on the official SDL website:
http://www.google.com/search?q=sdlmappy%20site:libsdl.org
It should also be noted that the “libraries,” “games,” “demos,” and
"applications" pages were cooked up by someone (Sam?) as a way to
voluntarily aggregate software using SDL, and probably also for these
software to get some attention from the SDL community, at its own
discretion. What all this means Two Eyed Human, is that you should ask
people who use SDLMappy. Try this link:
http://membres.lycos.fr/edorul/SDLMappye.htm
In the mean time, perhaps I can answer some questions that you may or
may not already know the answers to (in fact, you haven’t even asked
any of these questions.)
#define COMPLAINANDEXIT(x) { MessageBox(NULL, x ,“Error”,MB_OK);
exit(1); }
This is a bad idea to use after initializing SDL and many other
libraries. The reason is because many libraries require you to
explicitly uninitialize them.
#include <sdl/sdl.h>
In your IDE or compiler options, you should tell your compiler to look
for headers in the folder containing your SDL headers. Do not include
sdl/sdl.h. It won’t work on many many systems.
#include <SDLMappy.h>
#include <windows.h>
Why are you including windows.h? I don’t see you using anything from
windows.h in your code.
SDLMappy * map = 0;
SDL_Surface * screen = 0;
Uint8 * keys;
int x = 0;
int y = 0;
SDL_Event event;
int main(int argc, char * argv[])
{
??? if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)???
??? ??? COMPLAINANDEXIT(“Couldn’t initialize SDL!”);
??? atexit(SDL_Quit);
??? screen = SDL_SetVideoMode(640,480, 24, SDL_SWSURFACE);
??? if (screen == NULL)
??? ??? COMPLAINANDEXIT(“Could not make screen”);
??? map = new SDLMappy();
??? if (map->LoadMap(“mymap.fmp”, 0, 0, 400, 400) < 0)
??? ??? COMPLAINANDEXIT(“Couldn’t load mymap.fmp”);
??? int done = 0;
??? while(done == 0)
??? {
??? ??? SDL_PollEvent(&event);
??? ??? keys = SDL_GetKeyState(NULL);
One thing that occurs to me here is that you are only polling one event
each loop. This probably won’t cause your problem, but basically what
this WILL do is only process one key every time you go through the
loop, during which you draw your map and flip your back and front
buffers.
??? ??? if (keys[SDLK_UP]) y-=1;
??? ??? if (keys[SDLK_DOWN]) y+=1;
??? ??? if (keys[SDLK_LEFT]) x-=1;
??? ??? if (keys[SDLK_RIGHT]) x+=1;
??? ??? if ( event.type == SDL_QUIT )? {? done = 1;;? }
??? ??? ??? if ( event.type == SDL_KEYDOWN )
??? ??? ??? {???
??? ??? ??? ??? if ( event.key.keysym.sym == SDLK_ESCAPE )
??? ??? ??? ??? {
??? ??? ??? ??? ??? done = 1;
??? ??? ??? ??? }??
??? ??? ??? }
??? ??? map->MapMoveTo(x,y);
??? ??? map->MapChangeLayer(0);
??? ??? map->MapDrawBGT(screen);
??? ??? map->MapMoveTo(x,y);
Why do you call MapMoveTo() twice?
??? ??? SDL_Flip(screen);
??? }
??? return 0;
}
You didn’t even uninitialize SDL! Call SDL_Quit() before exiting your
application!On Jun 8, 2005, at 9:56 PM, wrote: