【发布时间】:2023-04-08 01:29:01
【问题描述】:
我在monogame subreddit中问过这个问题并得到了答案,但我很困惑。
我这样设置了一个数组:
Vector2D[] parallaxEffect = new Vector2D[2];
那么对于更新函数,代码如下
var mState = Mouse.GetState();
Vector2 translatorVector = mState.Position - _centerPosition;
//or _oldMousePosition
我对 _centerPosition 或 _oldMousePosition 有点困惑。我以为它是屏幕的中心,所以我像这样为它做了一个变量
Vector2 _centerPosition = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.Preferred.BackBufferHeight / 2);
(无论我的游戏的游戏分辨率设置为屏幕中心。)
这只会导致错误..说
运算符“-”不能应用于“Point”和“Vector2D”类型的操作数
对于将产生这种视差效果的实际图像是:
_layerOffset[0] = translateVector * 1.0f
_layerOffset[1] = translateVector * 0.5f
在抽奖中
spriteBatch.Draw(textureLayer1 = new Vector2(400, 300)+ _layerOffset[1],Color.White();
spriteBatch.Draw(textureLayer0 = new Vector2(400, 300)+ _layerOffset[0],Color.White();
他说这是一个非常基本的原理,但我还是不太明白。这里有人可以帮忙吗?提前谢谢你!
【问题讨论】: