Scripts:Large Portraits
Difficulty | Easy |
Skills | Loading and freeing slices |
Placing slices |
Introduction[edit]
This script allows the use of large portraits. This does not, however, allow for their use with default text boxes. Instead, these portraits can be used in custom dialogue/text box systems or for custom combat engines. Alternatively, it can be used for any situation that uses the built-in screens as containers for smaller graphics.
The most obvious advantage of this is that it allows the use of larger portraits. Another advantage is that it is possible to use more colors for each portrait, up to 256, rather than being limited to 16. It is also possible to use portraits of varying sizes, to impractically small 6×6 portraits to likewise impractically large 200×200 portraits. Currently, this script is configured for 64×80 portraits, not much larger than the current 50×50, but still noticeably larger.
You are free to use this script in whatever manner you choose. No attribution whatsoever is necessary.
Usage[edit]
This script contains three parts, the declaration of globals, the configuration script, and the actual loading script.
Globals[edit]
This section of the script simply declares globals to be used. There are four globals declared:
- psht - Portrait Sheet. This is the number of the first screen where portraits are stored.
- pcnt - Portrait Count. This is how many portraits are stored in each screen.
- pxsz - Portrait X Size. The width of each portrait.
- pysz - Portrait Y Size. The height of each portrait.
Configuration[edit]
The configuration section allows changing of the four globals mentioned above. There are default values stored already, and to change these, simply edit the script to fit your needs.
Loading[edit]
This is the main script that loads portraits. Using the script is essentially the same as any other script that loads sprites. To use it, type, "load large portrait(x)" where x is the number of the portrait to be loaded. Portraits are numbered on a screen from left to right, and from top to down, with the top left being 1. Any number can be entered, provided you have that many portraits. The script will automatically calculate which screen your requested portrait is on based on the configuration settings.
Like other slice loading scripts, this will return the handle for the slice created. This way, it is possible to manipulate it in the same manner as any other slice. And like any other slice, it can be freed once it is no longer needed.
Closing[edit]
All portraits are stored in screens. The number of portraits that can be stored on a single screen depends on the size of each individual portrait. However, because these portraits are stored in screens, it is strongly advised that at the start of development, a certain block of screens (e.g. 10-20) be set aside solely for the use of portraits. While it is possible to intersperse portrait screens with non-portrait screens, this will get very messy, very quickly. Further, it will be difficult to find the correct number for the specific portrait required.
Lastly, note that in this script, the globals psht, pcnt, pxsz, and pysz are not used anywhere else. Because of this, the globals can be eliminated and included within the main loading script. The only reason that they are separate now is that in the game I developed this script for (Legacy) those four variables are also used elsewhere and in other scripts, hence the separation. If you have no intention of using those four anywhere else, then it's suggested that you simply merge them.
#Globals #========================================================================================================= global variable, begin 9001, psht #The starting screen to be used for getting the portrait 9002, pcnt #The number of portraits to a screen 9003, pxsz #X size of each portrait 9004, pysz #Y size of each portrait end #========================================================================================================= #Configuration #========================================================================================================= script, portrait config, begin psht := 10 pcnt := 10 pxsz := 64 pysz := 80 end #========================================================================================================= #Loading #========================================================================================================= script, load large portrait, pnum, begin #Declare the variables #--------------------- variable( cslc #Container slice sslc #Sheet slice, where all the portraits are located scnt #Sheet count, the number on the sheet where the portrait is rcnt #Row Count, the number on the row where the portrait is snum #Screen number, the screen where the portrait is located sx #Sheet X, where it should be placed sy #Sheet Y, where is should be placed prow #Portrait Rows, the number of rows pcol #Portrait Columns, the number of columns crow #Current Row ccol #Current Column ) #--------------------- #Generate the Variables #---------------------- snum := ((pnum -- 1) / pcnt) + psht scnt := pnum -- ((snum -- psht) * pcnt) prow := 200 / pysz pcol := 320 / pxsz crow := ((scnt -- 1) / pcol) + 1 ccol := (scnt -- (crow * pcol)) + pcol sx := ((ccol -- 1) * pxsz) * -1 sy := ((crow -- 1) * pysz) * -1 #---------------------- cslc := create container(pxsz, pysz) #Create a container that's 64×80, the size of large portraits set slice clipping(cslc, TRUE) sslc := load backdrop sprite(snum) set parent(sslc, cslc) put slice(sslc, sx, sy) return(cslc) end #=========================================================================================================