Difference between revisions of "Display.install"

From MiniScript Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:
  
 
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.)
 
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.)
 +
 +
Note that when a display is freshly installed into a layer, the layer is automatically switched to that mode.  However, if the display is already in the layer where you are trying to install it, then the call has no effect — it does not automatically switch to that mode.  If you want to be sure a display is both installed and visible, you can always do something like:
 +
 +
<ms>myDisp.install layerIndex  // (where layerIndex is the layer we want it to be in)
 +
display(layerIndex).mode = myDisp.mode</ms>
  
 
=== Known Issues ===
 
=== Known Issues ===
 
Installing a [[PixelDisplay]] resets its [[PixelDisplay.color|color]] to white.  (Do not depend on this behavior; it may change in a future release.)
 
Installing a [[PixelDisplay]] resets its [[PixelDisplay.color|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 ===
 
=== Example ===

Latest revision as of 01:09, 7 February 2023

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.)

Note that when a display is freshly installed into a layer, the layer is automatically switched to that mode. However, if the display is already in the layer where you are trying to install it, then the call has no effect — it does not automatically switch to that mode. If you want to be sure a display is both installed and visible, you can always do something like:

myDisp.install layerIndex  // (where layerIndex is the layer we want it to be in)
display(layerIndex).mode = myDisp.mode

Known Issues

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

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