所以这是我的问题我需要精灵在特定位置移动: -
当精灵的底部距离屏幕顶部600像素时,将垂直方向从下行屏幕更改为上屏幕。
当精灵的右边缘距屏幕左边200像素时,水平方向从右到左,从左到右改变
当精灵的上边缘距离屏幕顶部400像素时,将垂直动作从上屏幕更改为下屏幕。
当精灵的左边缘距离屏幕左侧0像素时,将水平方向从右向左改为左右移动。
所以这就是我目前正在使用屏幕的两侧,任何帮助将不胜感激。
void Disc::Update(double totalTime, double timeDelta)
{
// function for calculating displacement is time * velocity
// timeDelta is how much time has passed since the last update call
DirectX::SimpleMath::Vector2 toMove = this->discVelocity * timeDelta;
this->spritePosition = this->spritePosition + toMove;
if (this->spritePosition.x >= (screenWidth - this->spriteWidth))
{
// reverse velocity ( set negative)
this->discVelocity.x = this->discVelocity.x * -1;
//this->spriteEffect = D DirectX::SpriteEffects::SpriteEffects_FlipHorizontally;
}
else if (this->spritePosition.x < 0)
{
// reverse velocity
this->discVelocity.x = this->discVelocity.x * -1;
//this->spriteEffect = DirectX::SpriteEffects::SpriteEffects_None;
}
else if (this->spritePosition.y >= screenHeight - 100)
{
this->discVelocity.y = this->discVelocity.y * -1;
}
else if (this->spritePosition.y <= 0)
{
this->discVelocity.y = this->discVelocity.y * -1;
}
}