Answers to your coding questions…

A site about answers….not questions

dovoto On August - 25 - 2012

Using the new windowing API to enable and display a window

First, as always, lets look at the full source for the demo. Notice that it sets up and displays our traditional drunkencoders logo, enables the window and finally lets us mess with its settings.

The DS has 3 hardware windows which can be used to mask parts of the screen. Two of them are simple rectangles, you give the DS the top, bottom, right, and left of the square and it creates a mask of that size. We can control what layers are rendered inside the window and which ones are rendered outside the window.

The other window is an Object Window and it uses a sprite object as the mask (basically any pixel in the sprite that is not zero becomes “in window”).

All that is required to use a window is first to turn it on, second to define if you want your layers or objects to appear inside the window or outside all windows, and finally define the top, left, bottom, and right positions of the window..

This brings us to our first bit of code to enable a window and set how that window effects our background.

If we did not set our background window options the background would neither show up inside nor outside the window and therefor would not be displayed. It is perfectly acceptable to have the bg show up inside multiple windows or outside all windows or both (just OR the window options together which you pass to bgWindowEnable).

We next set the starting x, y, and size of our window box:

Next is our main loop:

Inside this loop we alter the x and y with key presses so the window moves about, we adjust the size as well so we can shrink of grow it.

We also add a little feature that allows us to alter the window by pressing X and Y keys. Pressing Y tells the DS to display the part of the background that is outside all windows, pressing Y causes it to display only inside window 0. If you were to not call bgWindowDisable to turn off the unwanted option the background would simply end up being displayed both inside window 0 and outside all windows.

Finally, we set the bounds on our window based upon the settings we had altered above:

Categories: Tutorials

3 Responses

  1. Loaded a copy-and-paste of the entire source into Programmers Notepad, added my own BMP file.

    In attempting to compile, I get errors/warning with the Windows items (bgWindowEnable, WINDOW_0, etc). I assume there is an #include missing, or a system path needed. Any help would be appreciated.


  2. Hmm, would this be the above mentioned “new windowing API”???

    • dovoto says:

      Yes, sorry. I dont think this update is in the current version of libnds. Ill take a look at where it is in the pipeline (every since we switched to GIT things have become fuzzy with regard to source control)

    Leave a Reply

    Featured Video