|
Title: Backgrounds in DSLua 0.2 Post by: waruwaru on March 09, 2006, 12:33:10 PM You can think of backgrounds like layers of transparencies laying one on top of each other. There are many different kinds of backgrounds, such as bitmap, tiles, or text backgrounds. When you draw on a background, your drawing can obscure the stuff on the other backgrounds. You can have maximum of 4 layers of backgrounds (depending on what kind of backgrounds they are) on each screen. DSLua 0.2 supports a background for text output (TextBackGround) and an 8-bit bitmap background (8BitBackGround).
To use a background, you first need to load a background object using a function in the Screen library: Code: -- creates a background for text output BGTopText = Screen.LoadTextBG() -- creates a background to use as a bitmap for pixel level functions BGTop8Bit = Screen.Load8BitBG() In the future version, DSLua will allow you to initialize the background with your own picture files, or tile sets. Once the backgrounds are created, you need to initialize the screen with the order you want to layer your backgrounds. This function below will initialize the top screen with a text background and an 8 bit bitmap background. Since BGTopText is passed to the Screen.Inialize function before the BGTop8Bit background, it means any text you create on the text back ground will show up in front of the bitmapped back ground. You can not use a single background object to initialize 2 screens at the same time. Code: -- init top screen with 2 backgrounds, text in front of bitmap Screen.Initialize( 1, BGTopText, BGTop8Bit ) A text back ground object supports the following functions. Since a each specified background is different from others, you need to use the : instead of a . Code: -- set the color of the text TextBackGroung:«»SetColor( color ) -- print a string at location x, y on the screen TextBackGroung:«»PrintXY( x, y, string ) -- fill a rectangular area on the text background with specified character -- (x1,y1) is top left corner of the rectangle -- (x2,y2) is bottom right corner of the rectangle TextBackGroung:FillRectWithChar( x1, y1, x2, y2, character ) -- clears the text background TextBackGroung:Clear() A text back ground object supports the following functions. Since a each specified background is different from others, you need to use the : instead of a . Code: -- this function sets the color at index with a specified red/green/blue value -- on an 8 bit background, the index can be 0-255, red/green/blue can be 0-31 8BitBackGround:«»SetPaletteColor( index, red, green, blue ) -- plot a single pixel at location (x,y) using color in palette at index i 8BitBackGround:«»Plot( x, y, i ) -- draw a line from (x1,y1) to (x2,y2) using color in palette at index i 8BitBackGround:Line( x1, y1, x2, y2, i ) -- clears the bitmap background 8BitBackGround:Clear() |