Stopping my ViewCenter Camera!

Started by
2 comments, last by willthiswork89 18 years, 3 months ago

void DrawTiles()
{


    int TileC = (int)(ViewCenterX / TileW);
    int TileR = (int)(ViewCenterY / TileH);

    float OfsX = -(ViewCenterX - TileC*32);
    float OfsY = -(ViewCenterY - TileR*32);

    int TileCInit = TileC - 10;
    int TileRInit = TileR - 8;

    for(int col = 0; col < 21; col++)
    {
        for(int row = 0;row < 16; row++)
        {
            int YCoord = (int)(row*32 + OfsY);
            int XCoord = (int)(col*32 + OfsX);

            BlitTile(XCoord, YCoord, TileCInit+col, TileRInit +row);
        }
    }
}

okay the tiling engine is working good! no i have the question of how to stop my view center from going outside of the Map Area.. Considering that im horribl e at math but i do know this ViewCenter starts from the middle so i think that is take ViewCenterX - SWIDTH/2 that will give me the x edge of my "camera" but i still dont know how to stop it? any suggestions. mainly some math i need help with.. Thanks so much!
Advertisement
Surely you'd just need to check to make sure the camera doesn't go any further from the edge of the map than (distance to center)?

Sorry, I know what I'm trying to say, but having trouble explaining what I mean tonight!
void CheckCamera(){    int TileC = (int)((ViewCenterY - SHEIGHT/2)/32);    int TileR = (int)((ViewCenterX - SWIDTH/2) /32);        if((ViewCenterX + SWIDTH/2) <= (xPos + Wizzy_Width))        {            ViewCenterX += 15;        }        if((ViewCenterX -SWIDTH/2) >= (xPos))        {            ViewCenterX -= 15;        }        if((ViewCenterY + SHEIGHT/2) <= (yPos + Wizzy_Height))        {            ViewCenterY += 15;        }        if((ViewCenterY - SHEIGHT/2) >= (yPos))        {            ViewCenterY -= 15;        }        if(TileC < 0)        {            ViewCenterY += 15;        }}



this is what i have and as you can see th TileC < 0 ...its workin but its a bit glitchy i didnt finish the rest of it... it does goto the border because i think it rounds it? so im not sure how to fix that....
could anyone help? i could imagine it shouldnt be too hard.. ive played with it but im sure someone has a code or somthing that could help me out?

This topic is closed to new replies.

Advertisement