Sign in to follow this  

Rotating tiles?Or making many tiles?

This topic is 3839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
Hidden
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!

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Hidden
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!

Share this post


Link to post
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. ^_^

Share this post


Link to post
Share on other sites

This topic is 3839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this