XNA isometric tiles rendering issue -


i'm working on xna game prototype. i'm trying achieve isometric view of game world (or othographic?? i'm not sure right term projection - see pictures). world should tile-based world made of cubic tiles (e.g. similar minecraft's world), , i'm trying render in 2d using sprites.

so have sprite sheet top face of cube, front face , side (visible side) face. draw tiles using 3 separate calls drawsprite, 1 top, 1 side, 1 front, using source rectangle pick face want draw , destination rectangle set position on screen according formula convert 3d world coordinates isometric (orthographic?).

(sample sprite: sprite)

this works long draw faces, if try draw fine edges of each block (as per tile grid) can see random rendering pattern in lines overwritten face , not.

please note world representation, x left right, y inside screen outside screen, , z down.

in example i'm working top face-edges. here (picture):

alt text

i don't understand why of lines shown , not. rendering code use (note in example i'm drawing topmost layers in each dimension):

/// <summary> /// draws world /// </summary> /// <param name="spritebatch"></param> public void draw(spritebatch spritebatch) {     texture2d tex = null;      // draw tiles     (int z = numblocks - 1; z >= 0; z--)     {         (int y = 0; y < numblocks; y++)         {             (int x = numblocks - 1; x >=0 ; x--)             {                  mytextures.trygetvalue(myblockmanager.getblockat(x, y, z), out tex);                 if (tex != null)                 {                     // top face                     if (z == 0)                     {                         drawtop(spritebatch, x, y, z, tex);                         drawtop(spritebatch, x, y, z, outlinetexture);                     }                      // front face                     if(y == numblocks -1)                         drawfront(spritebatch, x, y, z, tex);                      // side face                     if(x == 0)                         drawside(spritebatch, x, y, z, tex);                  }             }         }     } }   private void drawtop(spritebatch spritebatch, int x, int y, int z, texture2d tex)         {             int px = offsetx + (int)(x * texture_top_x_offright + y * texture_side_x);             int py = offsety + (int)(y * texture_top_y + z * texture_front_y);             topdestrect.x = px;             topdestrect.y = py;             spritebatch.draw(tex, topdestrect, texture_top_rect, color.white);            } 

i tried using different approach, creating second 3-tiers nested loop after first one, keep top face drawing in first loop , edge highlight in second loop (i know, inefficient, should avoid having method call each tile draw it, i'm trying working now).

the results somehow better still not working expected, top rows missing, see picture:

alt text

any idea of why i'm having problem? in first approach might sort of z-fighting, i'm drawing sprites in precise order shouldn't overwrite what's there?

thanks everyone

whoa, sorry guys i'm idiot :) started batch spritebatch.begin(spritesortmode.backtofront) didn't use z-value in draw. should have used spritesortmode.deferred! it's working fine. everyone!


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -