Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple Isometric Render

Started by by Apr 25, 2006 at 9:09 AM 6 replies 2.6k views
Original Post
by
by
Hi everyone, I wanted to learn about isometric view in games, i searched web but couldn't find much articles. Most of them were for flash games which i've never used and couldn't understand rendering loops. Anyway, i have a tile like this: http://img100.imageshack.us/img100/2617/tilebase0hg.png I store map like this: struct MAP{ int tile[20][20]; }map; I'm rendering with this: for(int i=0; i<20; i++){ for(int a=0; a<20; a++){ if(map.tile[a] == 1){ DrawIMG(tile_base, i*42, a*21);//since my tile is 42x21 } } } And i am getting this: http://img100.imageshack.us/img100/7387/clipboard012as.jpg As you can see, its not a good isometric view :) How can i render tiles just more like an isometric game :) NOTE: I looked gamedev.net's article section, but i couldn't find something helps to me :)
jdarling
jdarling
Start by reading all of the resources available at: http://www.gamedev.net/reference/list.asp?categoryid=44

Thats the section on this site containing articles about Isometric Engines and other such things. Basically you have to render using the following formula:
tile_x = (starty and 1) * not(loopy and 1) or (not(starty and 1)) * (loopy and 1)))*(ChipWidth div 2)-OfsX  tile_y = loopy*(ChipHeight div 2)-(ChipHeight div 2)-OfsY


What this does is calculates the tile position based on; Every other row must be offset by 1/2 the tile width. Rows are overlaid by 1/2 tile height.

Reading the above will explain the reasoning behind the math I use. OfsX and OfsY are simply for fine control of map movement instead of rough (tile based) movement.

- Jeremy
by
by
Thanks, i will be at these articles then.

By the way, if you using/used, which is good to you? Hexagonal or Isometric?
jdarling
jdarling
Isometric and Hex each have their applications. I'll use the term Typically loosely in saying that; Typically Isometric is for RPG types of games while Hex falls into more of a board style along the lines of Risk. Really it comes down to standard movement patterns. In isometric you have 4 or 8 directions of movement, in Hex you have 6 or 12 directions of movement. The lower number movements are always 1:1 with the higher being 2:1 on scale. Again the articles point out the differences and their usages.

- Jeremy
by
by
My render code now looks like this:

picw=100;
pich=76;
for(int i=0; i<20; i++){
for(int a=0; a<20; a++){
if(map.tile[a] == 1){
DrawIMG(tile_base, (i*picw/2)-picw, (a*pich+((i%2)*pich/2))-pich);
}
}
}

It working. Thanks :)
Mattox
Mattox
Just a note for your own convenience, I had the same set-up as yours (except my isometric view was birds-eye, much more simpler and uglier to work with).

I used the int[][] concept for storing tile IDs too, and did an if/else statement for each tile. In the end, after I had ~60 or more tile types, this method became somewhat less than the worst efficiency can get if you know what I mean.

It might save you shitloads of time if you create your own Tile class to start off with. Converting your entire game to use a Tile[][] class array instead of an integer array is much easier. Then you can make the tiles store an abundance of info, like their size, position, type, cell id, you can even go as far as I went and name each tile individually (well I didn't name all of my many tiles, just made the ability to name it for future convenience. This Tile class idea allows me to assign scripts and triggers to tiles).

I don't know what language you're using, but I used Java. And an example in Java would be:

[sourcelang=java]public class Tile {    int type;    int cell;    boolean accessible; //can be walked on    int x, int y;    String name;        public Tile(int x, int y)    {        this.x = x;        this.y = y;    }        public final void Render()    {        //render code    }}


Then my main editor would do your loop above, but instead of 60 individual DrawImages, all I had to do was TileAt[column][row].Render();

WAY faster, easier to handle, cooler and much more efficient in most aspects.

You can even go so far as to implementing the Serializable interface in Java (I don't know the equivillent in any other language, but it just means you can 'write' directly to an object file, and read directly from an object file. For example, to load/save a map:

[sourcelang=Java]void save()   objectOutputStream.writeObject(TileAt[column][row]);void load()    TileAt = (Tile[][])objectInputStream.readObject();


Extremely rough, but I hope you get the idea. If not, ignore me and try asking someone who's had more sleep.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.