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´m trying to wrap my head around how to get this done, if at all possible. So basically I have a Area class, Map class and Tile class. My Area class is a singleton, and this is causing some confusion. I´m trying to draw like this: Background / Tiles / Entities / Overlay Tiles / UI.

void C_Application::OnRender()
{
    // Fill the screen black
    SDL_FillRect( Surf_Screen, &Surf_Screen->clip_rect, SDL_MapRGB( Surf_Screen->format, 0x00, 0x00, 0x00 ) );

    // Draw background

    // Draw tiles
    C_Area::AreaControl.OnRender(Surf_Screen, -C_Camera::CameraControl.GetX(), -C_Camera::CameraControl.GetY());

    // Draw entities
    for(unsigned int i = 0;i < C_Entity::EntityList.size();i++)
    {
        if( !C_Entity::EntityList[i] )
        {
            continue;
        }

        C_Entity::EntityList[i]->OnRender( Surf_Screen );
    }

    // Draw overlay tiles

    // Draw UI

    // Update the Surf_Screen surface
    SDL_Flip( Surf_Screen);
}

Would be nice if someone could give a little input. Thanks.

share|improve this question

1 Answer 1

Are you using the tutorials from SDLTutorials.com?

Assuming you're following the tutorials and don't want to modify things too heavily yet, you could create two rendering functions for C_Area: C_Area::OnRender(...) which would function exactly the same as it already does and C_Area::OnRenderOverlay(...) which would be called after your entities are drawn:

// Draw tiles
C_Area::AreaControl.OnRender(Surf_Screen, -C_Camera::CameraControl.GetX(), -C_Camera::CameraControl.GetY());
 
 
// Draw entities
for(unsigned int i = 0;i < C_Entity::EntityList.size();i++)
{
    if( !C_Entity::EntityList[i] )
    {

        continue;

    }

C_Entity::EntityList[i]->OnRender( Surf_Screen );

}

// Draw overlay tiles
C_Area::AreaControl.OnRenderOverlay(Surf_Screen, -C_Camera::CameraControl.GetX(), -C_Camera::CameraControl.GetY());

In C_Area's variables, you would then have to maintain another std::vector<CMap> that would be read in like the first map, except the data file you're reading would contain information about your overlay tiles. You would have to modify the OnLoad function to read it. C_Area::OnRenderOverlay(...) would simply draw the data associated with this vector on top of everything else.

Alternatively... redefine C_Area so it's not a singleton?

share|improve this answer
    
Thanks for your response, I did think about adding a map for the overlay and adding a OnRender method for that one. It´s just that I´m "pretty" new to this and just wanted to get a better grasp on if that would be a good idea, or just plain bad design in some way. Thanks again. –  Tony Sep 16 '12 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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