Simple Tilemap Scrolling
very basic tile map scrolling code example using OpenGL
float offsetx = 0; float offsety = 0; I am using the Tiling in OpenGL tutorial here at GDNet by Martin Estevao. Now, just add offsetx to every x of each tile's vertices, and add offsety to every y of every tile's vertices. void draw_tiles(GLvoid) { int tile; for (int y = 0; y < MAP_SIZEY; y++) { for (int x = 0; x < MAP_SIZEX; x++) { tile = map[y][x]; glBindTexture(GL_TEXTURE_2D, texture[tile]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x+offsetx), float(y + offsety), 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x + 1 + offsetx), float(y + offsety), 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x + 1 + offsetx), float(y + 1 + offsety), 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x + offsetx), float(y + 1 + offsety), 0.0f); glEnd(); } } } There, easier to understand in code than words. Next, go to wherever your input is and check to see if the Right key is held down. If it is, subtract 0.04 from offsetx. Check the Up key and if it is held down, subtract 0.04 from offsety. If the Down key is held down, add 0.04 to offsety. If the Left key is held down, add 0.04 to offsetx. I used 0.04 because it worked well with my computer speed and FPS I was getting. if((GetKeyState(VK_LEFT) & 0x80)) { offsetx += 0.04f; } if((GetKeyState(VK_RIGHT) & 0x80)) { offsetx -= 0.04f; } if((GetKeyState(VK_UP) & 0x80)) { offsety -= 0.04f; } if((GetKeyState(VK_DOWN) & 0x80)) { offsety += 0.04f; } And that's it! I hope you liked my super-simple scrolling, it is easily portable to directx from opengl and is easy to understand and implement. Another advantage is that now you don't need a playerx and playery variable, since the player is always at 0,0! This is where I leave you to go out and do some tile-based programming on your own. Good luck with whatever tile-based stuff you do, if you have comments or hating, send me an email at brandonmanrules@gmail.com, contact me on the forums as brandonman or post a comment in the feedback thread. Also, I'd be proud to know if this was used in any games you make, so tell me if it is! Thanks for taking the time to read this. Don't forget to download the source code as well!
Related Tutorials
Balancing Game Development and Creative Direction in Indie Production
A practical look at how indie developers can balance creative direction with hands-on game development. This article co…
My Unreal Engine Development Process: From Core Idea to Playable Build
A practical overview of my Unreal Engine development process, covering how I move from a core game idea to a playable b…
Introducing LaneGraph: The Ultimate Road Network Solution for Unity
Discover the power of LaneGraph, a lightweight and flexible lane-based navigation system for Unity. LaneGraph makes it…
Retargeting Mixamo Characters with Root Motion In Unreal Engine 5.4.
I have always found Retargeting Mixamo Characters To have Root Motion is a serious lengthy Tast, Recently I stumbled up…
How To Make A SIMPLE Main Menu In Unity
In this tutorial for unity, i go over how to make a simple main menu for unity, it's an unlisted video because i do not…
Guide to Gameplay Balance
A perspective on competitive gameplay balance, from a background of "shooter" sandbox design.
Discussion
More from Brandon H
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion