Rotating tiles?Or making many tiles?

Started by
5 comments, last by Fukushuusha 16 years, 10 months ago
I am making a 2D strategy game with SDL and I have this question. Since up to now I have been using placeholder graphics so I can progress the game engine I had not ran into this question. But now I really need to ask this to you. What is better? To have many tiles in my map? Either terrain tiles or units e.t.c. in many positions (looking up, left , right diagonal e.t.c? ) or use an SDL method to rotate them? Also which method might that be? I am gonna google it now, but if anyone answers my first question answering the second one too would not be bad :) EDIT: Also adding another question. Sorry if I am overwhelming with questions. by reading around this forum there seem to be many people who complain about SDL being slow, especially for a game like an RTS. Many think a solution would be openGL combined with SDL. Should I start thinking about that too? And if so ... any tutorials to change from plain SDL to openGl and SDL? Also .... would that take days of revising my code? :/ Again ..thanks for bearing with me and my questions.
Advertisement
I don't know about methods to rotate 2D picture that is looking left and make it look to back, rotating between left and right I think is possible but left and front/back I don't know about methods to do it.

Hmm any way about rotation u can use matrices (google->Matrix transform), I don't know how to rotate SDL_Surface, my teacher told me so there are some methods like moving all row of pixels and flip it and multiply by so matrix and you will get a rotated image.

Also you don't need to have "many tiles", You can have one image and insert into this image all your rotated tiles and each frame to draw only the one you need.
Hope my post was helpful.

I would love to change the world, but they won’t give me the source code.

As long as everything's in 2D you might as well go with many tiles/pictures rather than rotating them. Making sure each tile is rotated the right way all the time is probably a lot more work than it's worth, tiles don't take a lot of resources anyway.

It's a tradeoff though, as always. Do some calculations to see if you can afford to have all the tiles you need (which you probably will) or if you want/need to re-use as much as possible.
If you use OpenGL with your tile rotations, the graphics card will likely do all of the tile rotations for you faster than the CPU can do it with the SDL_gfx rotozoom function. Generally the rotozoom is used for precalculating rotations while OpenGL does it in realtime and saves video memory in the process.

If you don't know how to set up OpenGL to do this for you, I'd recommend looking though the source code of hxRender and use it if you like. The only catch is that you have to thank the author in the game credits or documentation if you use it. (It's under the ZLib license.)
If the graphics you're using for your units are top-down (and I mean 100% top-down), then I would definitely recommend using OpenGL and rotating them. Not only will it save you lots of time having to draw every unit in 4-8 different angles, but it will also save diskspace. Plus, you can rotate in any direction 360 and make some nice effects, like cars turning around, etc etc. Good luck!
Quote:Original post by Pzc
tiles don't take a lot of resources anyway.

Four rotation angles mean that your tiles will use four times the disk/video memory. This isn't a big deal if you only have a few different types of terrain, but keep in mind that tiles can use a significant amount of resources if you're wasteful.

OpenGL will certainly be faster than just SDL alone, but if you aren't familiar at all with OpenGL it will also be a decent learning curve. I guess it depends on why you are creating the game: is the extra technical challenge something you want to take on? If not, is it harming your product to have potentially higher system requirements? (Note: if you're just making it as a hobby game, probably not)

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

Thanks for all the nice answers. Actually the game is a hobby game. It is in no way a product for any company or team. The catch though is that I want to learn through it. Also friends who are also computer engineering students have shown interest to help and maybe just maybe I might have a small team of friends at my hands. So if it will help in speed I am considering changing to openGl + SDL even if it is 2D graphics.

Sorry for being late in replying but my graphics card burned out(mysteriously, I was coding when it happened... no pressure on the card) and I had to go buy a new one. So the new question is ... do you know of any tutorials of hwo to switch a project from plain SDL , to openGL + SDL?

Thanks in advance people :)
Quote:So the new question is ... do you know of any tutorials of hwo to switch a project from plain SDL , to openGL + SDL?

It's actually easier than what you might think. What you basically do is set up an OpenGL screen through SDL, like this:

#include "SDL_opengl.h"

SDL_Surface *MainScreen;

MainScreen = SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL);

And that's it. From there on you can start using any OpenGL functions you'd like. You can use OpenGL for graphic purposes, while you use SDL for keyboard and mouse input, timers, etc etc, since OpenGL doesn't have those (afaik).

Here's a tutorial on how to get started doing 2D graphics in OpenGL:

http://lazyfoo.net/SDL_tutorials/lesson36/index.php

And also, take a look at this thread in which I posted some example code not long ago:

this thread

Good luck!
Oh thanks a lot :)

I had read lazy foos tutorials a long time ago when I first started with SDL. Did not know it had one with OpenGL and SDL. That's very nice. Thanks for the code too. ^_^

This topic is closed to new replies.

Advertisement