Display.install

From MiniScript Wiki
Revision as of 21:32, 26 October 2022 by JoeStrout (talk | contribs)
Jump to navigation Jump to search

Display.install installs a Display into one of the eight display layers in the Mini Micro virtual machine, replacing (and detaching) the previous display in that layer.

Arguments

Parameter Name Type Default Value Meaning
index number 0 display layer to install into, from 0 (frontmost) to 7 (back)

Usage Notes

Any Display object is either installed in one of the 8 display layers, or it is detached (off-screen). A display created with new is initially detached. It may be configured, drawn into, and otherwise used, but will be completely invisible to the user until it is installed by calling this method.

This may be used for page flipping: preparing a number of uninstalled (off-screen) displays ahead of time, and then installing them on the screen one at a time to produce animation. Installation of a display is very fast, so even if the preparation (drawing) takes a while, you can produce very smooth, flicker-free animation this way. (See example below.)

Known Issues

Installing a PixelDisplay resets its color to white. (Do not depend on this behavior; it may change in a future release.)

Once a dynamically created SolidColorDisplay has been installed and then removed, it can't be installed again. (True in Mini Micro 1.1; may be fixed in 1.2 or later.)

Example

This example demonstrates the page flipping technique by preparing 20 off-screen PixelDisplays, each with a different drawing of a clock hand. The displays are then installed successively into layer 5, creating an animated clock. (Note that for such simple drawing, page flipping is not necessary; but it makes a good example.)

clear
pages = []
for i in range(0,19)
	p = new PixelDisplay   // create a detached PixelDisplay
	p.clear color.black
	ang = 2*pi/20 * i
	p.line 480,320, 480+300*cos(ang), 320+300*sin(ang), color.yellow, 20
	pages.push p
end for

curPage = 0
while true
	pages[curPage].install 5  // install next PixelDisplay in layer 5
	wait 1
	curPage = (curPage+1) % 20
end while