• 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
BaneTrapper

Drawing tiles to a screen math problems

2 posts in this topic

Hello.
I have successfully stored and drew 4Regions of 25x25Tiles to screen and made camera to move around screen
Here is my function

But what i need is to draw only tiles that are on screen.
I am trying to save performance, cause i want to be efficient
Ani tips or hints would be userfull

Here is my function to draw all 4 region to screen;

[CODE]
void Area::DrawArea(int CamX, int CamY, App* obj_App)
{
int TileID = 0; //Holds TileID;
int RegionID = 0; //Holds RegionID
int surfW = ((*GETP_surf_Tileset())->w / TILE_SIZE); //For SDL_Rect crop
SDL_Rect crop,pos;
crop.w = TILE_SIZE;
crop.h = TILE_SIZE;
(*obj_App->GETP_surf_Screen());
for(int a = 2; a < 6; a++) /*HomeMade math to draw to correct position will went : "x= 0 y = 0", "x = 1, y = 0", "x = 0 y = 1", "x = 1 y = 1"
So we draw to correct place to screen*/
{
for(int y = 0; y < REGION_SIZE/*25*/; y++)
{
for(int x = 0; x < REGION_SIZE/*25*/; x++)
{
if(RegionList[RegionID].TileList[TileID].Layer1 == -1) /* Check if tile loaded failed */
{
TileID++;
continue;
}
crop.x = (RegionList[RegionID].TileList[TileID].Layer1 % surfW) * TILE_SIZE;
crop.y = (RegionList[RegionID].TileList[TileID].Layer1 / surfW) * TILE_SIZE;
pos.x = (x * TILE_SIZE) - CamX + ((a % 2) * 1000);
pos.y = (y * TILE_SIZE) - CamY + (((a-2) / 2) * 1000);
SDL_BlitSurface(surf_Tileset, &crop, *obj_App->GETP_surf_Screen(), &pos);
TileID++;
}
}
TileID = 0; //We set TileID to 0 for next RegionLoop
RegionID ++; //We increment Region for next loop so we draw correct tiles
}
}
[/CODE]
0

Share this post


Link to post
Share on other sites
Figure out which tile column is the first/last one on the screen and same for tile rows, then only loop across those. You can do this by comparing your tile's positions (top-left corner known from pos and width/height known from TILE_SIZE, which gives you the bottom-left corner) with the bounds of your window. Compare coordinates to do this, e.g. go over a tile row, and go "is the x coordinate less than zero, yes, keep going... yes, etc... ah, this one is more than zero, so this is the first tile in each row to be shown on the screen!" and so forth. You can actually also calculate quickly which tiles are the "boundary tiles" with a formula if your tiles are all the same size, but it's best you try and do it the explicit way first so you don't get confused.

Does it make sense? Edited by Bacterius
0

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1345824094' post='4973020']
Figure out which tile column is the first/last one on the screen and same for tile rows, then only loop across those. You can do this by comparing your tile's positions (top-left corner known from pos and width/height known from TILE_SIZE, which gives you the bottom-left corner) with the bounds of your window. Compare coordinates to do this, e.g. go over a tile row, and go "is the x coordinate less than zero, yes, keep going... yes, etc... ah, this one is more than zero, so this is the first tile in each row to be shown on the screen!" and so forth. You can actually also calculate quickly which tiles are the "boundary tiles" with a formula if your tiles are all the same size, but it's best you try and do it the explicit way first so you don't get confused.

Does it make sense?
[/quote]

Mhm interesting. But its not quite good approach to what i have currently done.
I am kinda rusty with english.

I am tinkering about 4h so far, Got done with so much math and stuff but its still missing some stuff i cant figure out.
As you are saying i do it like:
Store start location in loop
How much to loop in x , y
But i need to do it 4x times, DONE but i also need to shift tiles for Some amount so they are at correct position... and its complicated ^^.

Thanks on the tip, keep em coming.
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