Public Group

# Stopping my ViewCenter Camera!

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

## 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 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 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 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?

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013734
×