Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / problems with screen wrapping

Author
Message
qwerty michael 007
14
Years of Service
User Offline
Joined: 21st Feb 2010
Location:
Posted: 22nd Feb 2010 15:06 Edited at: 22nd Feb 2010 20:43
i have been having problems with making a screen loop so if the ship goes off the top of the screen it reappears at the bottom on the same x coordinate and if it goes off to the left or right it appears at the same y coordinate on the opposite side of the screen. here is the movement so far where pos[0] = X and
pos [1] = Y.

void Ship::Update()
{


if(::dbUpKey())
{
pos[0] += 5.0f*sinf(D3DXToRadian(fAngle));
pos[1] -= 5.0f*cosf(D3DXToRadian(fAngle));

}
else if (::dbDownKey())
{
pos[0] -= 5.0f*sinf(D3DXToRadian(fAngle));
pos[1] += 5.0f*cosf(D3DXToRadian(fAngle));

}
if (::dbLeftKey())
{
fAngle -= 3.0f;
}
else if (::dbRightKey())
{
fAngle += 3.0f;
}

i would probably write it in a separate if else statement but the code above might be helpful. thank you to anybody that can get me started.
qwerty michael 007
14
Years of Service
User Offline
Joined: 21st Feb 2010
Location:
Posted: 22nd Feb 2010 23:44
well thanks guys but i solved it by myself if anyone else is having this problem what i did was called a loop function at the end of the last then inserted this...


void Ship::Loop()
{
if (pos[0] < 1)
{
pos[0] = 640;

}

else if (pos[0] > 640)
{
pos[0] = 1;
}

if (pos[1] < 1)
{
pos[1] = 640;
}

else if (pos[1] > 640)
{
pos[1] = 1;
}
}

Login to post a reply

Server time is: 2024-03-28 13:38:13
Your offset time is: 2024-03-28 13:38:13