Computer Science Canada Tiling with SDL |
Author: | Zren [ Wed Apr 15, 2009 10:18 pm ] | ||
Post subject: | Tiling with SDL | ||
I've been learning C++ and SDL from LazyFoo.net. After awhile I decided to attempt at making a platformer, since I learn best when trying to convert the teaching into a game. Unfortunatly I can't seem to understand how to tile surfaces...properly. clip is the x,y,w,h of the source image that is being use to tile. My logic is this: Load Image. Split into three. Tile middle part. Send X,Y, Width & Height of Clip to function. Print to temporary Surface. Print temp surface to screen. I can't seem to understand why this won't work.
|
Author: | saltpro15 [ Fri Apr 17, 2009 5:24 pm ] |
Post subject: | RE:Tiling with SDL |
should work... what's your compile command? |
Author: | CodeMonkey2000 [ Fri Apr 17, 2009 9:07 pm ] |
Post subject: | RE:Tiling with SDL |
You do realize how small a 2x2 clip space is right? And outputImage will always equal null. Also I don't follow your logic in tile_surface. What are you trying to accomplish? Finally, the way lazyfoo structured his code is convenient for tutorials, and so it isn't very practical at all, you probably should reorganize it into something easier to reuse (make a library). With the current system you have to manually set up and pass the screen surface every time you start a new program. |
Author: | Zren [ Sun Apr 19, 2009 1:33 pm ] |
Post subject: | Re: RE:Tiling with SDL |
CodeMonkey2000 @ Fri Apr 17, 2009 9:07 pm wrote: You do realize how small a 2x2 clip space is right? And outputImage will always equal null. Also I don't follow your logic in tile_surface. What are you trying to accomplish? Finally, the way lazyfoo structured his code is convenient for tutorials, and so it isn't very practical at all, you probably should reorganize it into something easier to reuse (make a library). With the current system you have to manually set up and pass the screen surface every time you start a new program.
You do realize how small a 2x2 clip space is right? I meant a 2x2 Tile set. so if one tile was 20x20px, then the output should be 40x40px. Large enought to notice. And outputImage will always equal null. How? It is initialized as NULL, but I'm adding to it through the for loops. Do I have to initialize a size of a SDL_Surface? Library-smibrary. I need the practice of setting everything up. Maybe when I 'graduate' this tutorial I'll consider a library. |
Author: | CodeMonkey2000 [ Sun Apr 19, 2009 1:45 pm ] |
Post subject: | RE:Tiling with SDL |
You didn't allocate enough memory for the pixel data in outputImage. Didn't you get any run-time errors? EDIT: You may want to use SDL_CreateRGBSurface |
Author: | Zren [ Sun Apr 19, 2009 3:16 pm ] |
Post subject: | Re: Tiling with SDL |
Sick, I got it working. Thanks CodeMonkey. I had no run time errors though since I no error catching. I'm lazier than the foo himself. If there's something in the standard library then no I didn't. My compiler is Dev-C++. I'm also using the SDL libraries linked from lazyfoo's tutorials. And saltpro, thanks for posting, but I'm not sure what you meen by that unless it's the linker properties, since I'm using and IDE. The program compiles fine, and wasn't calling anything that wasn't already included in other programs from the tutorials. |
Author: | saltpro15 [ Sun Apr 19, 2009 4:16 pm ] |
Post subject: | RE:Tiling with SDL |
well Zren, I know some people compile with say g++ whatev.cpp -o game -lSDL when really you want g++ whatev.cpp -o game -lSDL_image. using the first compile command from the terminal/prompt generates errors while the latter doesn't and you didn't state you were using an IDE, so give me a break ![]() |
Author: | CodeMonkey2000 [ Sun Apr 19, 2009 5:17 pm ] |
Post subject: | Re: Tiling with SDL |
Zren @ Sun Apr 19, 2009 3:16 pm wrote: I had no run time errors though since I no error catching. I'm lazier than the foo himself. If there's something in the standard library then no I didn't. My compiler is Dev-C++. I'm also using the SDL libraries linked from lazyfoo's tutorials.
That doesn't matter, windows should have terminated your program. |