[英]Camera Jitters Matrix Camera
我使用的是平移矩陣來移動屏幕,但是當播放器與某個對象碰撞時,播放器會抖動,好像它想同時位於2個位置一樣。 似乎在塊將其推上時速度要繼續下降,我該如何解決呢?
視頻: 在這里
相機類別:
class Camera
{
public Vector2 Position;
Viewport viewPort;
public Vector2 cameraBounds;
public float wasGround;
public Matrix Transform()
{
var translationMatrix = Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0));
return translationMatrix;
}
public Player thing(Player player)
{
cameraBounds.X = player.Position.X - Game1.offset.X;
if (cameraBounds.X > 0)
Position.X = player.Position.X - Game1.offset.X;
else
Position.X = 0;
//Problem
cameraBounds.Y = player.Position.Y - Game1.offset.Y;
if (cameraBounds.Y > 0)
{
Position.Y = player.Position.Y - Game1.offset.Y;
if (player.goingUp == false && (wasGround != player.ground))
Position.Y = player.ground - Game1.offset.Y;
wasGround = player.ground;
}
else
Position.Y = 0;
return player;
}
public Camera(Viewport viewport)
{
viewPort = viewport;
}
}
我試圖通過添加玩家goingUp和ground if語句來解決該問題,但這沒有幫助。
我解決了 它與操作順序有關。 只需移動方法camera.thing(),如下所示:
// TODO: Add your update logic here
HandleInput(Keyboard.GetState());
player.Update(gameTime);
// delete from here
Time += (float)gameTime.ElapsedGameTime.TotalSeconds;
foreach (Block b in Blocks)
{
player = b.BlockCollision(player);
}
// place here
camera.thing(player);
說明:完成所有碰撞后,您必須設置攝像機位置。
當您靜止不動時我看到的是速度變化。 因此請嘗試將相機位置轉換為整數。 或如果速度接近0,則使速度精確為0。
cameraBounds.X = cInt(cameraBounds.X)
cameraBounds.y = cInt(cameraBounds.y)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.