Nintendo DS 上的图块图形中出现奇怪的条纹

发布于 2024-07-24 02:18:39 字数 1794 浏览 9 评论 0原文

我正在为 Nintendo DS 开发一款乒乓球游戏。 我正在使用 libnds 进行设置,并且遇到了一个非常奇怪的行为。 到目前为止,我只在模拟器中尝试过,但我使用了三个不同的模拟器,它们都表现出这种行为,所以我怀疑我做了一些坏事。

实际问题是,当我使用背景图层 1 或以上作为平铺图形时,我会在该图层上看到奇怪的条纹。 如果我使用背景层 0,问题就会消失,但由于它是最后渲染的,所以我实际上无法在另一层中绘制它,而我想要这样做。

我的设置代码:

void pong::setup_engine()
{
    // Setup DS graphics engine.
    // -------------------------
    videoSetMode(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE);
    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    vramSetBankB(VRAM_B_MAIN_BG_0x06020000);

    u8 *tileMemory = reinterpret_cast<u8 *>(BG_TILE_RAM(1));
    u16 *mapMemory = reinterpret_cast<u16 *>(BG_MAP_RAM(0));

    int bg0 = bgInit(1, BgType_Text8bpp, BgSize_T_256x256, 0, 1);
    int bg1 = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
    //bgScroll(bg0, 256, 256);

    u16 *ptr = bgGetGfxPtr(bg1);
    for (int y = 10; y < 128*60; y++)
    {
        ptr[y] = 0xFFFF;
    }

    BG_PALETTE[1] = grey0;
    BG_PALETTE[2] = grey1;
    BG_PALETTE[3] = grey2;
    BG_PALETTE[4] = grey3;
    BG_PALETTE[5] = grey4;
    BG_PALETTE[6] = grey5;
    BG_PALETTE[7] = grey6;

    // 32 here is not 32 bytes but 32 half-words, which is 64 bytes.
    swiCopy(CORNER_TILE, tileMemory, 32);
    swiCopy(TOP_TILE, tileMemory + 64, 32);
    swiCopy(SIDE_TILE, tileMemory + (64 * 2), 32);
    swiCopy(MAIN_TILE, tileMemory + (64 * 3), 32);

    swiCopy(MAP, mapMemory, 32*24);
}

在上面的代码中,我将第 1 层用于 bg0,这是我的平铺图形层。 这使得奇怪的条纹出现; 如果我像这样将其更改为 0,它将按预期显示:

int bg0 = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0, 1);

任何想法导致问题,以及解决方案是什么?

图片奇怪的条纹

I'm working on a pong game for the Nintendo DS. I'm using libnds to set things up and I've come across a very strange behaviour. So far I've only tried it out in emulators, but I use three different ones and they all exhibit this behaviour so I suspect I'm doing something bad.

The actual problem is that when I use background layer 1 or above for my tiled graphics, I get weird stripes all over that layer. If I use background layer 0 the problem goes away, but since that is rendered last, I cannot actually draw over it in another layer, which I want to.

My setup code:

void pong::setup_engine()
{
    // Setup DS graphics engine.
    // -------------------------
    videoSetMode(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE);
    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    vramSetBankB(VRAM_B_MAIN_BG_0x06020000);

    u8 *tileMemory = reinterpret_cast<u8 *>(BG_TILE_RAM(1));
    u16 *mapMemory = reinterpret_cast<u16 *>(BG_MAP_RAM(0));

    int bg0 = bgInit(1, BgType_Text8bpp, BgSize_T_256x256, 0, 1);
    int bg1 = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
    //bgScroll(bg0, 256, 256);

    u16 *ptr = bgGetGfxPtr(bg1);
    for (int y = 10; y < 128*60; y++)
    {
        ptr[y] = 0xFFFF;
    }

    BG_PALETTE[1] = grey0;
    BG_PALETTE[2] = grey1;
    BG_PALETTE[3] = grey2;
    BG_PALETTE[4] = grey3;
    BG_PALETTE[5] = grey4;
    BG_PALETTE[6] = grey5;
    BG_PALETTE[7] = grey6;

    // 32 here is not 32 bytes but 32 half-words, which is 64 bytes.
    swiCopy(CORNER_TILE, tileMemory, 32);
    swiCopy(TOP_TILE, tileMemory + 64, 32);
    swiCopy(SIDE_TILE, tileMemory + (64 * 2), 32);
    swiCopy(MAIN_TILE, tileMemory + (64 * 3), 32);

    swiCopy(MAP, mapMemory, 32*24);
}

In the above code I use layer 1 for bg0, which is my tiled graphics layer. This makes the weird stripes appear; if I were to change it to 0 like this, it would show up as expected:

int bg0 = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0, 1);

Any ideas what causes the problem, and what the solution is?

Image of weird stripes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狂之美人 2024-07-31 02:18:39

简单地看一下background.h,看起来您正在使用BG1 和BG2。 对于模式5,根据:

http://nocash.emubase.de/gbatek.htm

第 0 层和第 1 层是普通层,第 2 层和第 3 层是扩展层。 我不知道延长意味着什么。 如果您只想做普通的图块操作,您可能需要 bgInit 0 和 1,而不是 1 和 2。

您可以随意更改优先级,第 0 层不一定位于 1 层之上,等等。查看 BGxCNT 寄存器(BG0CNT , BG1CNT,...) 和优先级位。 现在,如果优先级是平局,那么是的,层数决定谁获胜。

a breif look at background.h makes it look like you are using BG1 and BG2. For mode 5, according to:

http://nocash.emubase.de/gbatek.htm

layer 0 and 1 are normal and 2 and 3 are extended. I dont know what extended means. If you want to just do normal tile stuff you probably want to bgInit 0 and 1 not 1 and 2.

You can change the priorities around at will, layer 0 is not necessarily on top of 1, etc. Look at the BGxCNT registers (BG0CNT, BG1CNT,...) and the priority bits. Now if the priority is a tie then yes the layer number determines who wins.

忆悲凉 2024-07-31 02:18:39

两件事情。 首先,条带化很可能是 VRAM 冲突,尽管距离我上次进行 DS dev 已经有一段时间了。 仔细检查您要复制图形和图块数据的位置。 模式 5 使用两个文本背景,如果它们以某种方式初始化,它们的行为应该完全相同,所以我不确定那里发生了什么。

无论如何,既然您有两个背景在工作,为什么不在寄存器中设置它们的优先级来交换它们的 z 顺序呢? 背景默认情况下仅按特定顺序绘制,您可以设置它们的优先级,让系统按您喜欢的任何顺序绘制它们。

Two things. For one, the striping is most likely a VRAM conflict, although it's been a while since I did DS dev last. Double check where you're copying your graphics and your tile data. Mode 5 uses two text backgrounds, which should be behaving exactly the same if they're initialized a certain way, so I'm not sure what's going on there.

In any case, since you have two backgrounds working, why not just set their priorities in their registers to swap their z order? Background are only drawn in a particular order by default, you can set their priority to have the system draw them in any order you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文