tile mapping

Started by
6 comments, last by AndyEsser 18 years, 3 months ago
I have a template map that i load into my program. I have a 2 dimensional array of numbers that represent the number tile to be used in the BIG map. how would i create a "CreateMap()" function that iterates through the array and draws each tile onto a surface (or other thing), then when rendering comes, draw just the one surface onto a quad and use that as the BIG map?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Advertisement
Please look at the articles section and try to find the answer there first. If you don't find it, please let me know as I'm considering writing article about tile-based games.

Sorry, I've misread your post (thanks Drew_benton for letting me know[smile]).
It is not a good idea to do that in OpenGL as the texture is probably going to be huge. Instead, use many quads and setup your texture to contain unique tiles.
Use the texture coordinates to select the actual tiles.

Cheers,
Pat.
i used to do that, but when my engine calls for a rotation and scaling feature for a layer, it would be extremely hard to calculate every quad and rotate and scale them appropriately... so i just figured if i can draw them onto one quad and just draw that one quad i would be good.
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
You could just use glRotatef() and glScalef() for rotating and scaling the quads, I don't see how that's complicated at all [smile].
well, for my layer class, i have of course the 2-dimensional short array. each specify the number tile to use for the layer. i use only one vector specifying the top left corner of the entire layer. when this is rotated about a certain point within the layer, i need to recalculate where the top-left corner would be so when it is to be rendered again and the camera is somwhere in the middle of the layer, it would look like the camera is spinning in place (when actually the layer is rotating in relation to where the center of the screen is.

i can do all that with only one coordinate, but when i need to recalculate EVER quad... that's just overwhelming...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Quote:Original post by EvilKnuckles666
well, for my layer class, i have of course the 2-dimensional short array. each specify the number tile to use for the layer. i use only one vector specifying the top left corner of the entire layer. when this is rotated about a certain point within the layer, i need to recalculate where the top-left corner would be so when it is to be rendered again and the camera is somwhere in the middle of the layer, it would look like the camera is spinning in place (when actually the layer is rotating in relation to where the center of the screen is.

i can do all that with only one coordinate, but when i need to recalculate EVER quad... that's just overwhelming...


This is what the modelview matrix is for. Every vertex you draw gets translated by it. How exactly you do this is dependant on how you currently specify your quads' coordinates, but most likely (your quads are in absolute or "world" coordinates) you'll want to push the matrix, translate to the reference point of the layer, scale, rotate, and translate back to the origin (the negative of your reference point) prior to your usual drawing code (prior to the drawing of the entire layer, NOT every quad). Then at the end of the drawing, you would want to pop the matrix, to restore it for future layers.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
wow.. i never thought of that.. i really need to get used to OpenGL. i'm still a little used to how DirectX works.

so wait, all i need to do is draw my quads as if they start from 0,0 and make it soom like they're even with the screen and untranslated except push a matrix with the correct rotation, scaling, and translation and OGL will do it all for me?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Yeap

This topic is closed to new replies.

Advertisement