• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AlanSmithee

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

10 posts in this topic

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 ([url="http://www.gamedev.net/topic/437754-sdl-zoom-source-bigger-than-the-screen/"]http://www.gamedev.net/topic/437754-sdl-zoom-source-bigger-than-the-screen/[/url]) 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
0

Share this post


Link to post
Share on other sites
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 [url="http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/"]http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/[/url]

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,
-1

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Ah ok..

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
[quote name='AlanSmithee' timestamp='1325448164' post='4898744']
Ah ok..

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

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.
0

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1325625003' post='4899386']
[quote name='AlanSmithee' timestamp='1325448164' post='4898744']
Ah ok..

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

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.
[/quote]

SFML doesn't do 3D though, so he might have to learn OpenGL eventually anyway :P (Allthough using OpenGL with SFML works aswell)
0

Share this post


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

Share this post


Link to post
Share on other sites

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  
Followers 0