Sign in to follow this  

Stopping my ViewCenter Camera!

This topic is 4401 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

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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 4401 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this