Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

Tile engine: rendering big characters...

This topic is 3796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im having trouble rendering characters that are bigger than the tile dimensions. I've changed my map drawing code so that its sorts everything by its Y value heres a shot of what Im having right now Photobucket it does not make any sense having a render like this, since I have only 1 loop for the world and other for characters

Share this post


Link to post
Share on other sites
Advertisement
My guess is that you've enabled depthbuffering. Disable it, and everything will be displayed in the order you render it.

Share this post


Link to post
Share on other sites
There are two possible issues:
1 - You render the characters/tiles in an intermixed way, and you're drawing that tree object after the monster.
2 - You're using depth buffering and the depth values in the object over-ride the monster.

Share this post


Link to post
Share on other sites
you guys mean the SpriteSortMode right?

none of the spritesortmodes gave me a fix, heres my actual spritebatch init

sprite_batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, camera.TransformMatrix);





my render loop if maybe that will help


public void Draw(SpriteBatch spriteBatch, ref Actor[] Actors, ref Camera camera)
{
Point min_clip = GetMinimumClip(ref camera);
Point max_clip = GetMaximumClip(ref camera, min_clip);

int draw_calls = 0;
for (int id_z = 0; id_z < map_data.Size.Depth; id_z++)
{
for (int id_y = min_clip.Y; id_y < max_clip.Y; id_y++)
{

for (int id_x = min_clip.X; id_x < max_clip.X; id_x++)
{
if (map_data.TileData[id_z, id_x, id_y].Id == (Int32)TileData.TILE_NULL)
{
continue;
}

// Draw tile x,y,z here

}

// Actor rendering
for (int count = 0; count < Actors.Length; count++)
{
if (id_z == 3) // actor layer
{
if ((Actors[count].origin.Y + Actors[count].collision_box.Height / 2) / (int)TileData.TILE_SIZE == id_y + (Actors[count].collision_box.Height / (int)TileData.TILE_SIZE))
{
Actors[count].Draw(spriteBatch);
draw_calls++;
}
}
}
}
}



Share this post


Link to post
Share on other sites
Well, change the mode to BackToFront and modify the Z-value of the sprites. Characters can have Z=-1, trees and stuff can have 0 and ground +1 or something.

Share this post


Link to post
Share on other sites
then that way trees will be rendered on top of characters no matter what.

but that gave me the idea to assign a depth value to each actor depending on its Y value that it is proportional to the number of layers (lowest layer - highest layer)

I'll post an update soon

Share this post


Link to post
Share on other sites
still nothing

any more ideas?

I was trying to use a depth factor to fill in into the spritebatch.draw() method

the depth was calculated like this:

//for actors
depth = (float)Actors[count].collision_box.Bottom / (float)GetHeightInPixels();
//for tiles
float depth = (float)dest_rectangle.Bottom / (float)GetHeightInPixels();
depth *= (float)id_z * 0.10f; // to diferentiate between layers

Share this post


Link to post
Share on other sites
Can you just change the loop so it does more than one pass? That looks like it would be the simplest solution. I normally do something like:

* Level graphics (in this case ground)
* Characters
* Foreground (in this case trees)

Otherwise the characters will normally always get covered by lower tiles.

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilNando
then that way trees will be rendered on top of characters no matter what.

but that gave me the idea to assign a depth value to each actor depending on its Y value that it is proportional to the number of layers (lowest layer - highest layer)

I'll post an update soon


Lower Z values will be rendered closer to the viewer. Althought you may want to avoid negative values.

Share this post


Link to post
Share on other sites
This is the way that I would approach this problem.

Render everything in horizontal tile strips from top of the screen to the bottom. For each tile, render the base, then render any foliage, then render any characters, then render any other features that go over the character, such as a low wall at the front of the tile that would cover the characters feet.

Using this method you don't need to do any depth sorting or checking, and tall objects based in a particular tile will correctly overlap any tiles 'behind' it, while objects of different fundamental types sharing a tile get the correct draw order with respect to each other.

This may be a silly question, but how on earth did you get the tree sprite and the ogre sprite to splice into each other like that? Have you broken them up into multiple parts?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!