Jump to content

  • Log In with Google      Sign In   
  • Create Account


[C++ / SDL] Zoom out & in on tilemap


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 AlanSmithee   Members   -  Reputation: 903

Like
0Likes
Like

Posted 29 December 2011 - 07:08 AM

Hello.

As the title say i want to be able to zoom in and out on a tilemap in SDL.
As i zoom, I want the tiles in the map and sprites that are not attached to the tilemap to scale at the same rate to keep proportions.

I also want to scale the hitbox at the same rate as well.

My question is, simply put: how?

I am not looking for a solution but rather a way to tackle this problem cous im at a loss.

I tried to search google, gamedev and other sources and found some information (http://www.gamedev.net/topic/437754-sdl-zoom-source-bigger-than-the-screen/) that comes close to what i am looking for but i dont fully understand the concept so i don't blindly want to use code i dont understand.

If there is a general "how to zoom tiles and sprites" or if you have any iformation or experience regarding this i would be very thankful for any tips on how to approach this problem.

the tiles and sprites are all devidable by 2 (32x32 tiles and 32x32, 64x32 sprites) and are regulare SDL_Surface* 's.

If it matters it is for a 2d top down view game.

Thansk in advance / AS

Sponsor:

#2 bombshell93   Members   -  Reputation: 198

Like
-1Likes
Like

Posted 29 December 2011 - 09:14 AM

the way to do it in XNA is a matrix that scales and offsets points. I'm pretty sure you could do the same with C++
Get a transform matrix for the 2D camera
Matrix Transform =
Position Translation * //Camera Position Translation
Rotation * //Camera Rotation
Scale * //Camera Scale / Zoom
Screen Translation //Finish by Translating the Transforms back inline with the screen
source http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/

I know that its in XNA, but it will work in anything else,
all it does is transform everything drawn by this matrix. As is shown, it supports (as I've explained it) the position of the camera, the rotation of the camera and the zoom of the camera,

#3 BeerNutts   Crossbones+   -  Reputation: 2191

Like
0Likes
Like

Posted 29 December 2011 - 11:06 AM

My suggestion would be to scrap SDL and move to SFML. Not only does it allow you to scale/rotate any image (using HW acceleration, unlike SDL) but it allows you to do the same using Views.

In this case, you'd create a View, and you can move your view however you want (left, right, back, forth, rotate, etc.). There's nothing fancy you need to do except understand SFML's Views

sfml-dev.org
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 AlanSmithee   Members   -  Reputation: 903

Like
0Likes
Like

Posted 31 December 2011 - 04:32 AM

Hi guys.

Thanks a bunch for your help.

bombshell: I would love to be able to write functions like that but as it is right now I lack in math-knowledge. I am planning to take advanced match and vectormath courses next semester and hopefully I can implement something in those lines after that.

BeerNutts: Alot of my friends have told me to go over to SFML and i am considering doing so. I guess this functionality is yet another reason to do so. As it is right now though I am not able to switch as this project is to be done in SDL and i have already coded quite alot and even if the learning time would be short I don't want to start learning new syntax as I feel that I finally have an "ok" grasp of SDL.

I ended up going with the SDL_gfx library, using the rotozoom functionality.

It works well and is easy to use, I do something in the lines of 1) scale the surfaces (if changed), 2) scale the hitboxes (if changed), 3) re-set the camera according to the new dimensions.

I am yet to try this in a "real" situation with alot of surfaces so it might turn out to be bad perfomance-vise and if so, I'll have to find something else.
I actually found some negative comments when googling regarding performance, so im not too sure about it.

The only problem with the zoomSurface() (which is the only rotozoom function that I'm using) is that it messes up the colorkeying if the smooth flag is on.
There seem to be some workarounds / hacks to fix this but for now i'll zoom without smooth as i'll only zoom out (scale down the original) and never make it larger then x 1.0 the original so it looks ok.

I'd like to take this opportunity to ask anyone that has experience with the SDL_gfx lib if there is a "correct" way to fix the colorkey problem and if you have something to say regarding performance.

Thanks again for your help and happy new year =)

#5 BeerNutts   Crossbones+   -  Reputation: 2191

Like
0Likes
Like

Posted 31 December 2011 - 05:28 PM

I used SDL_gfx just a bit when I was trying to do some rotating. It "worked" but it did everything in Software. Once I switched to SFML, I realized how bad SDL was.

Sorry to beat a dead horse, and I don't have an exact answer to your question, since I only did a little testing with it.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#6 AlanSmithee   Members   -  Reputation: 903

Like
0Likes
Like

Posted 01 January 2012 - 02:02 PM

Ah ok..

I'm just curious now but is it not true that you can use HW acceleration by using openGL with SDL?

#7 fastcall22   Crossbones+   -  Reputation: 2981

Like
0Likes
Like

Posted 01 January 2012 - 03:23 PM

It is true you can use OpenGL through SDL -- SDL provides the window and the message processing. Everything else has to be through OpenGL (read: SDL's blitting functions aren't automagically hardware accelerated nor can you mix SDL software rendering with OpenGL rendering [very easily, that is]).

#8 AlanSmithee   Members   -  Reputation: 903

Like
0Likes
Like

Posted 03 January 2012 - 05:46 AM

Hey fastcall22.

Thanks for claring that out.

The problem is solved atm and after this project I'll see if I'll try SFML or go on with learning openGL, There seem to be some nice "from SDL to openGL" tutorials out there.. Like the nehe one for example.

#9 BeerNutts   Crossbones+   -  Reputation: 2191

Like
0Likes
Like

Posted 03 January 2012 - 03:10 PM

Ah ok..

I'm just curious now but is it not true that you can use HW acceleration by using openGL with SDL?


Yes. Or, you could use an API that is already built on top of OpenGL, and does the HW accelration for you, and you odn't have to learn 2 API's (SDL and OpenGL).

I wonder what API set does this? Oh, I know, SFML! ;)

As an added bonus, you can also use OpenGL with SFML if you need more detail.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#10 SimonForsman   Crossbones+   -  Reputation: 5462

Like
0Likes
Like

Posted 03 January 2012 - 03:15 PM


Ah ok..

I'm just curious now but is it not true that you can use HW acceleration by using openGL with SDL?


Yes. Or, you could use an API that is already built on top of OpenGL, and does the HW accelration for you, and you odn't have to learn 2 API's (SDL and OpenGL).

I wonder what API set does this? Oh, I know, SFML! ;)

As an added bonus, you can also use OpenGL with SFML if you need more detail.


SFML doesn't do 3D though, so he might have to learn OpenGL eventually anyway :P (Allthough using OpenGL with SFML works aswell)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#11 AlanSmithee   Members   -  Reputation: 903

Like
0Likes
Like

Posted 04 January 2012 - 08:26 AM

Hi again.

lol point taken ;)

As i said earlier, switching API in the middle of this project might caus more trouble then it will do good.

I will be sure to really check out SFML once done though.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS