Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've currently been trying my hand at Isometric map rendering via the tutorial over at XNA resources; http://www.xnaresources.com/default.asp?page=Tutorial:TileEngineSeries:4

However, unfortuanely the map isn't quite rendering as you can see in this photo of my output; http://i.imgur.com/JdIRrOE.png

I've not too sure where i'm going wrong, here below is my rendering code;

        protected override void Draw (GameTime gameTime)

    {

        graphics.GraphicsDevice.Clear (Color.CornflowerBlue);



        //Set Up Screen Geo, see how many times we can display on the screen

        int tileOnX = ((int)scroll.X / tileWidth);

        int tileOnScreenX = (((tileOnX * tileWidth) + graphics.PreferredBackBufferWidth) / stepX) + 1;

        int tileOnY = ((int)scroll.Y / tileHeight);

        int tileOnScreenY = (((tileOnY * tileHeight) + graphics.PreferredBackBufferHeight) / stepY) + 1;



        if (tileOnScreenX > isoMap.getWidth())

            tileOnScreenX = isoMap.getWidth();



        if (tileOnScreenY > isoMap.getHeight ())

            tileOnScreenY = isoMap.getHeight ();



        //Set up Depth 

        float maxdepth = ((isoMap.getWidth() + 1) * ((isoMap.getHeight() + 1) * tileWidth)) / 10;

        //Locals

        int tileX, tileY;

        float depthOffset;



        spriteBatch.Begin (SpriteSortMode.BackToFront, BlendState.AlphaBlend);



        //Draw Iso Map

        for (int y = tileOnY; y < tileOnScreenY; y++)

        {

            int rowOffset = 0;

            if ((tileOnY + y) % 2 == 1)

                rowOffset = oddRowXOffset;



            for (int x = tileOnX; x < tileOnScreenX; x++)

            {

                //Draw Base Layer Cells

                foreach (int tileID in isoMap.rows[y].columns[x].getBaseCells()) {

                    //Get Current Tile

                    tileX = (tileID % numberOfTilesPerRow) * tileWidth;

                    tileY = (tileID / numberOfTilesPerRow) * tileHeight;



                    //Set Poisition Rect

                    basePosition.X = (x * stepX) - (int)scroll.X + rowOffset;

                    basePosition.Y = (y * stepY) - (int)scroll.Y + baseOffsetY;

                    basePosition.Width = tileWidth;

                    basePosition.Height = tileHeight;

                    //Set Source Rectangle 

                    baseImagePoisition.X = tileX;

                    baseImagePoisition.Y = tileY;

                    baseImagePoisition.Width = tileWidth;

                    baseImagePoisition.Height = tileHeight;



                    spriteBatch.Draw (tileSheet, basePosition, baseImagePoisition, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1.0f);

                }



                //Draw Core Layer Cells

                int heightRow = 0;

                depthOffset = 0.7f - ((tileOnX + (tileOnY * tileWidth)) / maxdepth);

                foreach (int tileID in isoMap.rows[y].columns[x].getCoreCells())

                {

                    //Get Current Tile

                    tileX = (tileID % numberOfTilesPerRow) * tileWidth;

                    tileY = (tileID / numberOfTilesPerRow) * tileHeight;



                    //Set Poisition Rect

                    corePosition.X = (x * stepX) - (int)scroll.X + rowOffset;

                    corePosition.Y = (y * stepY) - (int)scroll.Y + baseOffsetY - (heightRow * 32);

                    corePosition.Width = tileWidth;

                    corePosition.Height = tileHeight;

                    //Set Source Rectangle 

                    coreImagePoisition.X = tileX;

                    coreImagePoisition.Y = tileY;

                    coreImagePoisition.Width = tileWidth;

                    coreImagePoisition.Height = tileHeight;



                    spriteBatch.Draw (tileSheet, corePosition, coreImagePoisition, Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 

                                      depthOffset - ((float)heightRow * heightRowDepthMod));

                    heightRow++;

                }





            }

        }



        spriteBatch.End ();

        base.Draw (gameTime);

    }

}

Any help with this would be greatly appreciated. P.s - The base layer of tiles is rendering correctly just in case anyone was wondering, i just kept the entire base layer at tileID 0. *the plain grass tile you see in my output :)

share|improve this question

closed as too localized by Byte56, msell, Anko, Tetrad May 17 '13 at 18:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 1 down vote accepted
int mapx = (tileOnX + x);
int mapy = (tileOnY + y);
depthOffset = 0.7f - ((mapx + (mapy * tileWidth)) / maxdepth);

I forgot to add on the incrementing x & y values from the for-loop :/.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.