c++ directx9 center background

Hello,

i am trying to code some graphics for a little game in c++ and winapi / directx9.

I have established a background as a surface. Then i put some sprites on the background.

The problem is, as i call a function that has to center the screen on the active sprite, it doesn't show the background.

Here is the code so far, if you miss an information, please ask and i will answer.


First, the part of main, that is called, when user pushes button (winapi):
case ID_ZENTRIEREN:
{
for (int x=0;x<4;x++)
if (Spieler[x].Rundenaktiv==true)
{
Spielx=Spieler[x].posx;
Spiely=Spieler[x].posy;
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0);
render_frame_center(hDlg1, Worldposx, Worldposy, Bildschirmbreite, Bildschirmhoehe, Spielx, Spiely);
if (Spieler[x].Mobilart==0) //Schuerfer
{
float Mobilposx, Mobilposy;
Mobilposx=Spieler[x].posx;
Mobilposy=Spieler[x].posy;
render_Schuerfer(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
}
else if (Spieler[x].Mobilart==1) //Frachter
{
float Mobilposx, Mobilposy;
Mobilposx=Spieler[x].posx;
Mobilposy=Spieler[x].posy;
render_Frachter(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
}
else if (Spieler[x].Mobilart==2) //Flugwaechter
{
float Mobilposx, Mobilposy;
Mobilposx=Spieler[x].posx;
Mobilposy=Spieler[x].posy;
render_Flugwaechter(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
}
else if (Spieler[x].Mobilart==3) //Jaeger
{
float Mobilposx, Mobilposy;
Mobilposx=Spieler[x].posx;
Mobilposy=Spieler[x].posy;
render_Jaeger(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
}

render_ZeichenaktivesMobil(Spielx, Spiely, oWorldposx, oWorldposy);
render_frame_center(hDlg1, Worldposx, Worldposy, Bildschirmbreite, Bildschirmhoehe, Spielx, Spiely);
d3ddev->Present(NULL,NULL,NULL,NULL);

}
}
break;

As next, the function that should center the background:
void render_frame_center(HWND hDlg1, float &Worldposx, float &Worldposy, float &Bildschirmbreite, float &Bildschirmhoehe, float &Spielx, float &Spiely)
{
RECT screenRect;
GetClientRect(GetDlgItem(hDlg1, ID_KARTE),&screenRect);
RECT drawRect;
// Spieler im Feld
if (Spielx>(screenRect.right-screenRect.left)/2&&
Spielx<1600-(screenRect.right-screenRect.left)/2&&
Spiely>(screenRect.bottom-screenRect.top)/2&&
Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=Spiely+(screenRect.top-screenRect.bottom)/2;
drawRect.left=Spielx-(screenRect.right-screenRect.left)/2;
drawRect.right=Spielx+(screenRect.right-screenRect.left)/2;
drawRect.bottom=Spiely+(screenRect.top-screenRect.bottom)/2;
}
//links
else if (Spielx<(screenRect.right-screenRect.left)/2&&
Spielx<1600-(screenRect.right-screenRect.left)/2&&
Spiely>(screenRect.bottom-screenRect.top)/2&&
Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=Spiely+(screenRect.top-screenRect.bottom)/2;
drawRect.left=0;
drawRect.right=0+(screenRect.right-screenRect.left);
drawRect.bottom=Spiely+(screenRect.top-screenRect.bottom)/2;
}
//rechts
else if (Spielx>(screenRect.right-screenRect.left)/2&&
Spielx>1600-(screenRect.right-screenRect.left)/2&&
Spiely>(screenRect.bottom-screenRect.top)/2&&
Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=Spiely+(screenRect.top-screenRect.bottom)/2;
drawRect.left=1600-(screenRect.right-screenRect.left);
drawRect.right=1600;
drawRect.bottom=Spiely+(screenRect.top-screenRect.bottom)/2;
}
//oben
else if (Spielx>(screenRect.right-screenRect.left)/2&&
Spielx<1600-(screenRect.right-screenRect.left)/2&&
Spiely<(screenRect.bottom-screenRect.top)/2&&
Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=0;
drawRect.left=Spielx-(screenRect.right-screenRect.left)/2;
drawRect.right=Spielx+(screenRect.right-screenRect.left)/2;
drawRect.bottom=0+(screenRect.top-screenRect.bottom);
}
//unten
else if (Spielx>(screenRect.right-screenRect.left)/2&&
Spielx<1600-(screenRect.right-screenRect.left)/2&&
Spiely>(screenRect.bottom-screenRect.top)/2&&
Spiely>1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=1200-(screenRect.top-screenRect.bottom);
drawRect.left=Spielx-(screenRect.right-screenRect.left)/2;
drawRect.right=Spielx+(screenRect.right-screenRect.left)/2;
drawRect.bottom=1200;
}
// oben links
else if (Spielx<(screenRect.right-screenRect.left)/2&&
Spielx<1600-(screenRect.right-screenRect.left)/2&&
Spiely<(screenRect.bottom-screenRect.top)/2&&
Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=0;
drawRect.left=0;
drawRect.right=0+(screenRect.right-screenRect.left);
drawRect.bottom=0+(screenRect.top-screenRect.bottom);
}
// oben rechts
else if (Spielx>(screenRect.right-screenRect.left)/2&&
Spielx>1600-(screenRect.right-screenRect.left)/2&&
Spiely<(screenRect.bottom-screenRect.top)/2&&
Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=0;
drawRect.left=1600-(screenRect.right-screenRect.left);
drawRect.right=1600;
drawRect.bottom=0+(screenRect.top-screenRect.bottom);
}
//unten links
else if (Spielx<(screenRect.right-screenRect.left)/2&&
Spielx<1600-(screenRect.right-screenRect.left)/2&&
Spiely>(screenRect.bottom-screenRect.top)/2&&
Spiely>1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=1200-(screenRect.top-screenRect.bottom);
drawRect.left=0;
drawRect.right=0+(screenRect.right-screenRect.left);
drawRect.bottom=1200;
}
//unten rechts
else if (Spielx>(screenRect.right-screenRect.left)/2&&
Spielx>1600-(screenRect.right-screenRect.left)/2&&
Spiely>(screenRect.bottom-screenRect.top)/2&&
Spiely>1200-(screenRect.bottom-screenRect.top)/2)
{
drawRect.top=1200-(screenRect.top-screenRect.bottom);
drawRect.left=1600-(screenRect.right-screenRect.left);
drawRect.right=1600;
drawRect.bottom=1200;
}


d3ddev->BeginScene();

d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
d3ddev->StretchRect(Hintergrund, &drawRect, backbuffer, NULL, D3DTEXF_NONE);

d3ddev->EndScene();

}

Further information:
the surface has 800/600, but will be presented as 1600/1200.
int Spielx, Spielx==coordinates of the ship/ sprite

It would be great if someone helps me, because i didn't find a hint in my books or in web.
Topic archived. No new replies allowed.