如何制作视差背景?c# Monogame

本文关键字:Monogame 背景 何制作 视差 | 更新日期: 2023-09-27 18:05:24

我在网上搜索了所有东西,但我找不到一种方法来为我的标题屏幕制作简单的视差背景

如何制作视差背景?c# Monogame

一般来说,一种显示水平重复背景的方法,应该适用于任何能够显示图像的库:

image is a background image.
image2 is a second copy of the background.
On update:
    // Move the background to the left.
    image.x -= PerUpdateDeltaX;
    // If the background is off the screen, move it back on.
    // You can use modulo/remainder to do this better.
    if (image.x < -image.width)
        image.x = image.width;
    // Put the second image to the right of the first.
    image2.x = image.x + image.width;

为了让它看起来更好,背景图像的边缘需要是无缝的。

然后,要制作视差(在我看来,在3D中有多个图层移动),只需添加一些东西:

  1. 透明度。
  2. 更多对重复的背景图像,每层视差一对。
  3. 每层PerUpdateDeltaX值不同。为了看起来好看,较高/较近的图层应该比较低的图层移动得快。