1
Window / Re: How to get the 4 corners of a view (converted into world coordinates)
« on: August 01, 2015, 11:11:59 pm »
Ok, so I'm getting all of the coordinates correctly now. I'm able to keep the view within the map, but I'm having trouble allowing the camera to move one direction with the player but not the other. An example would be if the player is on the very left side of the map (so the x-direction of the camera stays within the map), but the y-axis of the viewport would move up and down. Here's some of the code I was trying to use, but it's not working as expected:
This is within my Camera::update() method.
static bool regularLeft = true;
static bool regularUp = true;
static bool regularRight = true;
static bool regularDown = true;
static auto xPos = 0.f;
static auto yPos = 0.f;
if (topLeft.x <= 0.f)
{
if (xPos == 0.f)
xPos = m_spriteToFollow->getPosition().x;
regularLeft = false;
if (m_spriteToFollow->getPosition().x > xPos)
regularLeft = true;
else
{
if ((regularUp && !regularDown) || (!regularUp && regularDown))
m_view.setCenter(xPos, m_spriteToFollow->getPosition().y);
else
m_view.setCenter(xPos, yPos);
}
}
if (topLeft.y <= 0.f)
{
if (yPos == 0.f)
yPos = m_spriteToFollow->getPosition().y;
regularUp = false;
if (m_spriteToFollow->getPosition().y > yPos)
regularUp = true;
else
{
if ((regularLeft && !regularRight) || (!regularLeft && regularRight))
m_view.setCenter(m_spriteToFollow->getPosition().x, yPos);
else
m_view.setCenter(xPos, yPos);
}
}
if (regularLeft && regularUp && regularRight && regularDown)
m_view.setCenter(m_spriteToFollow->getPosition());
static bool regularUp = true;
static bool regularRight = true;
static bool regularDown = true;
static auto xPos = 0.f;
static auto yPos = 0.f;
if (topLeft.x <= 0.f)
{
if (xPos == 0.f)
xPos = m_spriteToFollow->getPosition().x;
regularLeft = false;
if (m_spriteToFollow->getPosition().x > xPos)
regularLeft = true;
else
{
if ((regularUp && !regularDown) || (!regularUp && regularDown))
m_view.setCenter(xPos, m_spriteToFollow->getPosition().y);
else
m_view.setCenter(xPos, yPos);
}
}
if (topLeft.y <= 0.f)
{
if (yPos == 0.f)
yPos = m_spriteToFollow->getPosition().y;
regularUp = false;
if (m_spriteToFollow->getPosition().y > yPos)
regularUp = true;
else
{
if ((regularLeft && !regularRight) || (!regularLeft && regularRight))
m_view.setCenter(m_spriteToFollow->getPosition().x, yPos);
else
m_view.setCenter(xPos, yPos);
}
}
if (regularLeft && regularUp && regularRight && regularDown)
m_view.setCenter(m_spriteToFollow->getPosition());
This is within my Camera::update() method.