Nooby question:how to get mappy to scroll

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?

#include <sdl/sdl.h>
#include <SDLMappy.h>
#include <windows.h>

#define COMPLAINANDEXIT(x) { MessageBox(NULL, x ,“Error”,MB_OK); exit(1); }

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);
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);
SDL_Flip(screen);
}
return 0;
}–

have you tested to make sure your map->moveto function works?

i’d test it by itself, without having it rely on keypresses (ie every loop add 0.001 to y or something so you can see it scroll smoothly once you fire it up)----- Original Message -----
From: twoeyedhuman1111 at gmail.com
To: sdl at libsdl.org
Sent: Wednesday, June 08, 2005 6:56 PM
Subject: [SDL] nooby question:how to get mappy to scroll

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?

#include <sdl/sdl.h>
#include <SDLMappy.h>
#include <windows.h>

#define COMPLAINANDEXIT(x) { MessageBox(NULL, x ,“Error”,MB_OK); exit(1); }

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);
      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);
      SDL_Flip(screen);
  }
  return 0;

}




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

Okay, I have been working on this piece of code for the past day
or so, and it STILL WON’T SCROLL!!!11

What is a SDLMappy? Given how simple is the code, I’d take a look at
what is that thing doing.

    I am r3 at lly annoyed.

Maybe it doesn’t work cuz your not l337 nuff, d00d. SDL requires teh m4d
5killz0rz!

--Gabriel

You’re using SDL_Flip but you’re not using doublebuffered mode.
Either change the SDL_SetVideoMode call to SDL_SetVideoMode(640,480,
24, SDL_SWSURFACE | SDL_DOUBLEBUF) or change the SDL_Flip call to
SDL_UpdateRect(screen,0,0,0,0).On 6/9/05, Gabriel wrote:

    Okay, I have been working on this piece of code for the past day
    or so, and it STILL WON'T SCROLL!!!!!!!!!!!!!!!!!!!!!!!!!!!!11

What is a SDLMappy? Given how simple is the code, I’d take a look at
what is that thing doing.

    I am r3 at lly annoyed.

Maybe it doesn’t work cuz your not l337 nuff, d00d. SDL requires teh m4d
5killz0rz!

--Gabriel

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

Josh Matthews wrote:

You’re using SDL_Flip but you’re not using doublebuffered mode.
Either change the SDL_SetVideoMode call to SDL_SetVideoMode(640,480,
24, SDL_SWSURFACE | SDL_DOUBLEBUF) or change the SDL_Flip call to
SDL_UpdateRect(screen,0,0,0,0).

SDL_Flip() is equivalent to SDL_UpdateRect(screen,0,0,0,0) on
single-buffered surfaces.

–ryan.

please post the code for Mr Mappy.

that it the first place you should lookOn 6/8/05, twoeyedhuman1111 at gmail.com wrote:

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?

#include <sdl/sdl.h>
#include <SDLMappy.h>
#include <windows.h>

#define COMPLAINANDEXIT(x) { MessageBox(NULL, x ,“Error”,MB_OK); exit(1); }

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);
     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);
     SDL_Flip(screen);
 }
 return 0;

}



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

Why don’t you debug to see if the keypress isn’t ignored ?–

P.O.M.P.E.I. du 47-20

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: